Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

implicit vs explicit cast c#

// Implicit (converting from a smaller type to a larger type)
int anInt = 12;
float aFloat = anInt;

Console.WriteLine($"anInt: {anInt}"); // anInt: 12
Console.WriteLine($"aFloat: {aFloat}"); // aFloat: 12

// Explicit (converting from a larger type to a smaller type)
float aFloat = 12.945f;
int anInt = (int) aFloat;

Console.WriteLine($"aFloat: {aFloat}"); // aFloat: 12.945
Console.WriteLine($"anInt: {anInt}"); // anInt: 12
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# exception middleware 
Csharp :: csv to xml using xmldocument c# 
Csharp :: quaternion to euler 
Csharp :: change a positive number to negative or a negative number to positive 
Csharp :: restrictions 
Csharp :: animation not playing unity 
Csharp :: triangle 
Csharp :: static keyword 
Csharp :: c# exit foreach 
Csharp :: add to ienumerable 
Csharp :: round image unity 
Csharp :: how to use date range picker in asp.net C# 
Csharp :: ioptions mock c# unittest 
Csharp :: why does everything reset when switching scene unity 
Csharp :: c# null check 
Csharp :: Read csv file into wpf C# 
Csharp :: read only variable in c# 
Csharp :: public controller script unity 3d 
Csharp :: user (current login user) in viewcomponent 
Csharp :: HOW TO CALL AN EXTENSION METHOD FOR VIEW C# 
Csharp :: how to increase alpha in strings using unity 
Csharp :: how to check if data already exists in database in c# mvc 
Csharp :: mvc input number rounding 
Csharp :: get 24 hour time in c# 
Csharp :: quick watch in visual studio 
Csharp :: c# propertyinfo indexof 
Csharp :: imageLocation in C# 
Csharp :: where are the viwes in .net core publish 
Csharp :: get child index unity 
Csharp :: how to use mongodb search index in c# 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =