Tuesday 4 August 2015

String Vs string ?

string is an alias of System.String. string is reserved keyword in c# .net. Int32 Vs int is a similar situation as is BooleanVs bool.  To use string any time refering to an object.

Ex:-
string place = ”world”;

String (System.String) is a class in the base class library. To use String if you need to refer specially to a class.

Ex:-
string strText = String.Format("Helo {0}", place);

So technically there is no difference between string and String.

What is Nullable in.Net and how to use?

C# provided a special data type called as Nullable type. In Nullable type you can assign a normal range values i.e  -2,147,483,648 to 2,147,483,647 or null value also.

In int,string,float,double etc data type we can not assign null values.

int intNo = null; // compiler error : Cannot convert null to int because it is non-nullable value type

Syntax:

<data_type>?  <variable-name> = null;

Example :-

static void Main(string[] args)
{
   int? num = null;
   int? num = 45;
   string strWord = null;
   double? d = 3.478;
   object o = null;
   Console.WriteLine("{0},{1},{2},{3},{4}",num,num1,strWord,d,o);
   Console.ReadLine();
}


Output:   , 45 ,  ,3.478,