Immutable Dot Net strings
Posted
by klork
on Stack Overflow
See other posts from Stack Overflow
or by klork
Published on 2010-05-28T20:21:49Z
Indexed on
2010/05/28
20:32 UTC
Read the original article
Hit count: 296
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
© Stack Overflow or respective owner