C#.NET Interview Questions and Answers – Part 2
C# supports three different types of comments
– Single Line Comments Eg : //
– Multi Line comments Eg : /* */
– XML Documentation Comments Eg : ///
The predefined types in C# includes
Value types like Numeric , sbyte, short, int, long , byte, ushort, uint, ulong , float, double, decimal , bool , char.
Reference types like string , object.
The primitive types in C# are all the value types excluding decimal . The primitive types translates directly to support in the processor that the application is targeted for.
F – float
D – double
M – decimal
U – uint
L – long
UL – ulong
int Input1 = 100000001;
float Float1 = Input1;
int Output1 = (int)Float1;
Answer : 100000000
The reason for this behaviour is that when implicitly converting a large integer number to a floating point number , the precision may sometimes be lost .
By default , the when there is a overflow of the data during conversion or assignment , the overflowing happens silently and no exception is thrown. To make sure that there is an arithmetic overflow exception , use the checked operator or checked block.
The checked operator does not have any effect on the following datatypes – double , float , decimal.
double.NaN , float.NaN
double.PositiveInfinity , float.PositiveInfinity
double.NegativeInfinity , float.NegativeInfinity
?0.0 , ?0.0f
When the floating point number is divided by zero , this results in the infinity value.
Console.WriteLine ( 5.0 / 0.0);
The result will be Nan when we try to divide zero by zero or subtract infinity from infinity.
Console.WriteLine ( 0.0 / 0.0);