Cor Ligthert [MVP] <no************@planet.nlwrote:
And than he can use the d variable global inside your method as clear is
intended in the question?
Well, he could use the "d" variable anywhere else it's in scope,
because it's definitely assigned at that point - every branch the code
could take (regardless of i's value) assigns to d.
This is in my idea much easier in VB.Net and therefore is the question from
C#learner probably.
I could solve this only with
string d = "";
In the shortest notation I know while this is in VB.Net
dim d as string
That's still longer than the C# version :)
Which means an address declaration inside a method and not an assignment.
At that point, depending on the version/settings you will either get a
warning (the default with VB.NET in .NET 2.0) or you'll risk using the
variable before it's been assigned to without anything telling you (in
..NET 1.1). I prefer to be told about potential programming issues,
myself.
However maybe I oversee something and than I will be as well lucky with your
answer.
Well, my if/else answer would certainly work, but it's not as elegant
as:
string d = words[i];
where words is an appropriate list or array of strings...
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too