Labels

Monday, September 7, 2009

Conversion Myth

 

Input

Output

Object obj = null;               

 

string str1 = Convert.ToString(obj);

“”  (Blank)

string str2 = obj as string;

Null

string str3 = obj.ToString();

Exception – Object Reference not set to an instance of an object

 

 

Input

Output

Int? obj = null;               

 

string str1 = Convert.ToString(obj);

“”  (Blank)

string str2 = obj.ToString();

“”  (Blank)

 

 

Input

Output

Int obj = 0;               

 

string str1 = Convert.ToString(obj);

0

string str2 = obj.ToString();

0

 

 

Input

Output

string str = “”;

int i = Convert.ToInt32(str);

Exception  - Input string was not in a correct format

string str = “A”;

int i = Convert.ToInt32(str);

Exception  - Input string was not in a correct format

string str = null;

int i = Convert.ToInt32(str);

0

 

 

Input

Output

string str = “”;

int i = Int32.Parse (str);

Exception  - Input string was not in a correct format

string str = “A”;

int i = Int32.Parse (str);

Exception  - Input string was not in a correct format

string str = null;

int i = Int32.Parse (str);

Exception  - Value cannot be null.

 

 

Input string was not in a correct format.

 

 

 

Thanks & Regards,

Arun Manglick || Senior Tech Lead

 

 

No comments:

Post a Comment