0% found this document useful (0 votes)
16 views7 pages

6 C# Type Casting

Type casting involves converting a value of one data type to another type. There are two types of casting in C#: implicit casting, which automatically converts smaller types to larger ones, and explicit casting, which requires manually placing the target type in parentheses when converting larger to smaller types. Conversion methods like Convert.ToDouble and Convert.ToString can also explicitly cast between types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

6 C# Type Casting

Type casting involves converting a value of one data type to another type. There are two types of casting in C#: implicit casting, which automatically converts smaller types to larger ones, and explicit casting, which requires manually placing the target type in parentheses when converting larger to smaller types. Conversion methods like Convert.ToDouble and Convert.ToString can also explicitly cast between types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Welcome C# Type Casting

All

What is Type Casting ?


Implicit Type Casting
Explicit Type Casting
Conversion Methods
Follow

Content
Follow RAD Techno Services,
23/134, Swarn Path,
Mansarovar, Jaipur-302020

Email:- [email protected]
Website:- www.radtechnoservices.com
Follow
Follow
Conversion Methods

Explicit Type Casting


Implicit Type Casting

What is Type Casting ?


4.
3.
2.
1.
CONTENT

Explicit Type Casting.


Implicit Type Casting.
What is Type Casting?

Type Conversion Methods.

Content
Content
What is Type Casting ?
 Type casting is when you assign a value
of one data type to another type.

 In C#, there are two types of casting:

Explicit Type Casting


Implicit Type Casting
Conversion Methods

What is Type Casting ?


Introductio
 Implicit Casting (automatically) -

Follow
Follow
converting a smaller type to a larger
type size
char -> int -> long -> float -> double

 Explicit Casting (manually) -


converting a larger type to a smaller
size type
double -> float -> long -> int -> char
Implicit Type Casting
 Implicit casting is done automatically when
passing a smaller size type to a larger size
type.

What is Type Casting ?


Explicit Type Casting
Example:

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:

What is Type Casting ?


Implicit Type Casting
Conversion Methods

Explicit Type Casting


Example:

History
Follow
Follow double myDouble = 9.78;
// Manual casting: double to int
int myInt = (int) myDouble;

Console.WriteLine(myDouble); // Outputs 9.78

Console.WriteLine(myInt); // Outputs 9
Type Conversions Methods
 It is also possible to convert data types explicitly by
using built-in methods.

 Such as Convert.ToBoolean, Convert.ToDouble


Convert.ToString, Convert.ToInt32 (int)
and Convert.ToInt64(long)

What is Type Casting ?


Implicit Type Casting
Explicit Type Casting
How it works
Methods
Example:
Follow
Follow
int myInt = 10;
double myDouble = 5.25;

Conversion
bool myBool = true;

// convert int to string


Console.WriteLine(Convert.ToString(myInt));
// convert int to double
Console.WriteLine(Convert.ToDouble(myInt));
// convert double to int
Console.WriteLine(Convert.ToInt32(myDouble));
// convert bool to string
Console.WriteLine(Convert.ToString(myBool));
YOU
THANK

Follow
Follow
Conversion Methods
Explicit Type Casting
Implicit Type Casting
What is Type Casting ?

Content

You might also like