Immutable Dot Net strings
- by klork
I usually define my string variables in vb.net as
Dim f_sName as string=String.Empty
f_sName = "foo"
Given the immutable nature of strings in .net, is there a better way to initialize strings and deal with the "Variable 'f_sName ' is used before it has been assigned a value. A null reference exception could result at runtime." warning?
Also for classes that do not have constructors which accept no arguments such as System.Net.Sockets.NetworkStream, what is the best way to define and initialize a variable of that type?
All comments are highly appreciated.
Thanks