"Bill Baxter" <wbax...@gmail.com> wrote in message news:mailman.122.1254431062.20261.digitalmar...@puremagic.com... >> Probably more like
Foo f; createAndSetOutParam(f); f.bar(); or Foo f; if (a > 10) { f = new Foo(10); } ... if (a > 10) { f.bar(); } How does C# handle the cases above? << Just did a little test: --------------------------------------- static void Main(string[] args) { Foo f; if(args.Count() > 2) { f = new Foo(); } if(args.Count() > 2) { f.bar(); // ERROR: Use of unassgned local variable 'f' } Foo f2; createFoo(ref f2); // ERROR: Use of unassgned local variable 'f2' f2.bar(); } static void createFoo(ref Foo f) { f = new Foo(); } --------------------------------------------- The first one is rather strange coding though and makes it easy to hide errors anyway. And the second one's a tad odd too, plus I don't see any harm in solving that with "Foo f2=null": it would at least be a hell of a lot better than the compiler doing that very same "=null" automatically. I know Walter doesn't agree, but I'd much rather have a few slightly inconvinient false positives (or would it really be a false negative?) than even a mere possibility for a hidden error.