Hi Guys
NP134 null
In the following program string value is declared as a null. Is there any advantage of declaring string value as a null? Because string is a reference-type variable whereas null is a default value of reference-type variables.
Please explain.
Thank you
using System;
class MainClass
{
public static void Main(string[] args)
{
string formStr = null;
formStr = string.Format("you had {0:C} in your account?", 99989.987);
Console.WriteLine(formStr);
}
}
/*
you had $99,989.99 in your account?
*/
AlanPosted Aug 24, 2008, 11:23 AM
There's no point in assigning formStr a value of null when you're going to assign it a different value in the next line. If I'd been writing that code, I would have combined those two lines into one:
string formStr = string.Format("you had {0:C} in your account?", 99989.987);
Posted Aug 24, 2008, 11:34 AM
Thank you very much for explanation.