Data Type Conversions in C# with real time example
In This Post We Will Learn Data Type Conversions
1. Implicit Conversions
2. Explicit Conversions
3. Different between Parse() and TryParse()
Implicit Conversion is done by the compiler
1. When there is no loss of information if the conversion is done
2. if there is no possibility of throwing exception during the conversion
Example : Converting an int to a float will not loose any data and no Exception will be thrown,
hence an implicit conversion can be done.
using System;
namespace Datatypes_conversion
{
class Program
{
static void Main(string[] args)
{
// Implicit Convertion Real Time Example
int r = 100;
float m = r;
Console.WriteLine(m);
Console.ReadLine();
}
}
}
Example : Converting an int to a float will not loose any data and no Exception will be thrown,
hence an implicit conversion can be done.
Explicit Conversions:
Comments
Post a Comment