6 C# Type Casting
6 C# Type Casting
All
Content
Follow RAD Techno Services,
23/134, Swarn Path,
Mansarovar, Jaipur-302020
Email:- [email protected]
Website:- www.radtechnoservices.com
Follow
Follow
Conversion Methods
Content
Content
What is Type Casting ?
Type casting is when you assign a value
of one data type to another type.
Follow
Follow
converting a smaller type to a larger
type size
char -> int -> long -> float -> double
Conversion Methods
Type Casting
Requirement
Follow
Follow
int myInt = 9;
s
// Automatic casting: int to double
Implicit
double myDouble = myInt;
Console.WriteLine(myInt); // Outputs 9
Console.WriteLine(myDouble); // Outputs 9
Explicit Type Casting
Explicit casting must be done manually
by placing the type in parentheses in
front of the value:
History
Follow
Follow double myDouble = 9.78;
// Manual casting: double to int
int myInt = (int) myDouble;
Console.WriteLine(myInt); // Outputs 9
Type Conversions Methods
It is also possible to convert data types explicitly by
using built-in methods.
Conversion
bool myBool = true;
Follow
Follow
Conversion Methods
Explicit Type Casting
Implicit Type Casting
What is Type Casting ?
Content