Click here to Skip to main content
15,907,328 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Someone must have asked this before but what exactly is casting. i need a very crude explanation after which any/all the C# related words can be used.
Thank you. :)
Posted

A cast explicitly invokes the conversion operator from one type to another. The cast will fail if no such conversion operator is defined. You can write custom conversion operators to convert between user-defined types

http://g4ac.co.za/C-Sharp_Casting[^]

http://g4ac.co.za/5k5du[^]
 
Share this answer
 
v2
"If a conversion cannot be made without a risk of losing information, the compiler requires that you perform an explicit conversion, which is called a cast. A cast is a way of explicitly informing the compiler that you intend to make the conversion and that you are aware that data loss might occur. To perform a cast, specify the type that you are casting to in parentheses in front of the value or variable to be converted. The following program casts a double to an int. The program will not compile without the cast."


Can't get any more crude than this[^].
 
Share this answer
 
Comments
Uday P.Singh 15-Jul-11 15:45pm    
great explanation my 5!
Abhinav S 16-Jul-11 0:18am    
Thank you Uday.
cast is saying to the compiler: "I'm freaking aware the data types don't match, anyway I'm the Master and you just a tool, so shut up and compile this fuc#*n statement".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900