G Guest Aug 20, 2006 #1 hi, string s = Convert.ToString(null); why the 'Convert' class do not return "" ? how can it work ?
J John Timney \(MVP\) Aug 20, 2006 #2 null does not equal an empty string, which is what your expecting Convert to give you. You should initilaize string s as string.Empty or evaluate it against null then just assign it to string.empty. if (s == null){ s = string.Empty; } Regards John Timney (MVP)
null does not equal an empty string, which is what your expecting Convert to give you. You should initilaize string s as string.Empty or evaluate it against null then just assign it to string.empty. if (s == null){ s = string.Empty; } Regards John Timney (MVP)
J John Timney \(MVP\) Aug 20, 2006 #4 It converts a base data type to another base data type - if you pass null you get null back as null doesn't have an underlying type (its a reference type pointing to nothing), its not appropriate for converting as it converts null to null. The convert class is described here, pehaps you can work out what you can use it for: http://msdn2.microsoft.com/en-us/library/system.convert.aspx s = Convert.ToString ((object)null); Casting to object before the conversion should give you string.empty as a return type. Regards John Timney (MVP)
It converts a base data type to another base data type - if you pass null you get null back as null doesn't have an underlying type (its a reference type pointing to nothing), its not appropriate for converting as it converts null to null. The convert class is described here, pehaps you can work out what you can use it for: http://msdn2.microsoft.com/en-us/library/system.convert.aspx s = Convert.ToString ((object)null); Casting to object before the conversion should give you string.empty as a return type. Regards John Timney (MVP)