What is the difference between "Convert" class and "Parse()" method?

 Posted by Tripati_tutu on 3/23/2011 | Category: C# Interview questions | Views: 4946 | Points: 40

>>> The Convert class is used to convert any value from any data type to another data type. This class consist of different methods for making conversions.
1) char ch = Convert.ToChar("x"); -> string to character
2) float f = Convert.ToSingle(45); -> int to float
3) int x = Convert.ToInt(4.5f); -> float to int

>>> The Parse method is used to convert only one string value to any other data type. Every data type is consisting of parse() method.
1) int x = int.Parse("600"); -> string to int
2) char ch = char.Parse("dnf"); -> string to character

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response