Realize: What are the sort changes in C#.Net, kinds of type transformations and how they can be utilized to change over one information type’s an incentive to another in C#.
Type change is an essential and significant element of practically all programming dialects, Type transformation is utilized to change over one kind of information into another sort. It is otherwise called sort throwing.
There are two sorts of type throwing/transformations utilized in c#:
- Verifiable or programmed type throwing
- Unequivocal sort throwing
1) Implicit or programmed type throwing
Certain sort throwing is acted in a type-safe way in c#. At the point when we convert information from littler to bigger basic sort and change from kid class to the parent, class is known as verifiable kind transformation.
2) Explicit sort change
This change isn’t performed naturally. For express sort changes, we have to utilize pre-characterize capacities. At some point, we have to utilize some change administrators.
Think about the program:
using System;
class Sample
{
static void Main(string[] args)
{
double var1 = 3.245;
int var2 = 0 ;
//Convert double to int
var2 = (int)var1;
Console.WriteLine(var2);
}
}
Output:
3
In the wake of accumulating and executing the above program, the outcome will be 3.
In the above program, var1 variable is twofold type yet we are changing over its incentive to int and allotting to var2.