"Jon Skeet [C# MVP]" <sk***@pobox.com> a écrit dans le message de news:
MP************************@msnews.microsoft.com...
| No - it's not assumed to be null. It's not definitely assigned. Big
| difference :) If it were assumed to be null, you wouldn't get a
| compile-time error, you'd get a NullReferenceException at run-time.
You are right, it's early and my brain isn't yet communicating clearly :-)
| > The purpose of the out modifier is to allow the
| > same funtionality as returning a reference from a function and should be
| > treated as such. Its purpose is to return references from a method not
to
| > pass references into it.
|
| Indeed. The reason the OP is getting the error message, however, is
| that the actual argument must be a variable of exactly the same type as
| the output parameter.
Agreed. I think the problem is that the OP does not yet understand what the
out modifier actually does.
private void TestOut(out BaseClass value)
{
value.Test();
}
This code actually raise two errors :
Error 1 Use of unassigned out parameter 'value' F:\Test\Form1.cs 31 7 Test
Error 2 The out parameter 'value' must be assigned to before control leaves
the current method F:\Test\Form1.cs 29 18 Test
So the OP's examples definitely won't compile for other reasons than the
faulty parameter type. These errors make it clear that an out parameter
*must* be assigned something and not used to pass something in.
Can I wake up now ? :-)
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer