c# - Explicit assignment of null -


string s1; string s2 = null;  if (s1 == null) // compile error if (s2 == null) // ok 

i don't understand why explicit assignment needed. whats difference between null variable , unassigned variable? assumed unassigned variables assigned null runtime/compiler anyway. if they're not null, they?

unassigned members automatically initialized default values (which null reference in case string).

unassigned local variables not assigned value , trying access possibly unassigned variable give compile error.


Comments

Popular posts from this blog

silverlight - Applying a style to ItemContainerStyle in C# -

c# - NullReferenceException in MySqlClient.NativeDriver -

php - Updating recent updates - Problem in procedure - Any other approach? -