Default values
In general there are two types of variables
1. Class variables & 2. Local variables
Class variables are the variables declared in the class scope Whereas Local variables are the variables declared locally within particular function. Local variables should be initialized before using it otherwise it will through a compilation error, but class variables are differ even without initializing also we can use it because by default default_values will be added.
Following are the default values assigned to the class variables
Bool - false; Char - \u0000; Sbyte - 0; byte - 0; short - 0; ushort - 0; int - 0; uint - 0; long - 0; ulong - 0; float - 0.0f; double - 0.0d; decimal - 0.0m; Sbyte - 0 ;Sbyte - 0 Sbyte - 0
Basic conversion
A basic method for implicit conversion is destination should be big enough to hold the value means size of the destination type should be bigger than the source type so that there is no loss of data. Legal implicit conversion for C# types Sbyte --> short, int, long, float, double, decimal byte --> short, ushort, int, uint, long, ulong, float, double, decimal int --> long, float, double, decimal float --> double double & decimal --> None
If the distination size is smaller than the size of the source type then we need to explicitly mention cast of the type, In this case probability of loss of data is high this is known as explicit conversion
Eg: Double maxWgt = 53.71; Float minWgt = (float) maxWgt;
---------------------------------------------------------------------
|
No responses found. Be the first to respond and make money from revenue sharing program.
|