what is the diference between casting and converting?

Answers were Sorted based on User's Feedback



what is the diference between casting and converting?..

Answer / kiran vaidya

When you use Convert class, you have some predefined types
which are defined by .Net framework such as Convert.ToInt32
or Convert.ToString and so on. That means you can convert
whatever you want to only system defined types.

while in casting, you can have your own choices to convert
data. i.e. user defined types.

for eg. you have a class called Employee and you want to
convert some object to Employee, then the best way to do
this is casting.

Is This Answer Correct ?    10 Yes 0 No

what is the diference between casting and converting?..

Answer / praveen

The Convert.ToInt32(String, IFormatProvider) underneath
calls the Int32.Parse. So the only difference is that if a
null string is passed to Convert it returns 0, whereas
Int32.Parse throws an ArgumentNullException.

It is really a matter of choice whichever you use.

Also have a look at the new .NET 2.0 method Int32.TryParse,
which attempts to convert a string to an int without
throwing an exception.

Is This Answer Correct ?    8 Yes 0 No

Post New Answer

More C Sharp Interview Questions

how background thread access to ui control?

0 Answers   HCL,


How can we give strong name to assembly? What is satellite assembly?

2 Answers   SMNetserv,


What is unmannaged code and will CLR handle this kind of code or not .

0 Answers   DELL,


Advantages of c# over vb.net?

3 Answers   HCL, Syntel,


What is an extension method in c#?

0 Answers  






Are tuples immutable c#?

0 Answers  


the selected inf of other combobox?How do you achieve it?

1 Answers   CTS, Microsoft,


what is output parameter and parameter array?

1 Answers   TCS,


What is .net console?

0 Answers  


What is class and object c#?

0 Answers  


What is difference between assembly and dll?

0 Answers  


What is the size of a decimal?

0 Answers  


Categories