2

What is the differences between Casting and Conversion operation in C#. Please explanation in simple way for beginners.

Thanks for your help!

Resources: http://msdn.microsoft.com/en-us/library/ms173105%28v=VS.100%29.aspx

GibboK
  • 71,848
  • 143
  • 435
  • 658
  • why don't you try a web search for example at Wikipedia – David Heffernan Jan 10 '11 at 10:30
  • 1
    possible duplicate of [What is the difference between casting and conversion?](http://stackoverflow.com/questions/3166840/what-is-the-difference-between-casting-and-conversion) – David Heffernan Jan 10 '11 at 10:39
  • 1
    David thanks, I am really a beginner and I looked many times online but I cannot find an EASY explanation. – GibboK Jan 10 '11 at 10:39
  • 1
    Since this is a duplicate, the question will likely soon be closed. You would likely be more successful if you re-phrased the question and tried to explain what you found difficult to understand. The Wikipedia article and the many questions on Stack Overflow seem easy to understand to me. The crux will be that you are lacking some vital piece of understanding, but until you take the time to write down what aspect you find difficult to grasp it's hard to help. – David Heffernan Jan 10 '11 at 10:41
  • Thanks David for sure I will take in consideration your advices :-) thanks for now – GibboK Jan 10 '11 at 11:15

3 Answers3

3

Casting is an attempt to change the type of a variable without changing the representation (so casting an int to a long doesn't change the underlying structure).

Converting is changing the type and the internal representation (converting a string to an integer - very different internal representations).

Oded
  • 489,969
  • 99
  • 883
  • 1,009
1

You have different type of conversion, casting is one of them.

1

To cast is to temporarily treat one type as another type where as to convert is to permanently change it.

Dan Diplo
  • 25,076
  • 4
  • 67
  • 89