C#.NET Interview Questions and Answers – Part 2
11. What are the different type of comments provided by C# for documentation ?
C# supports three different types of comments
– Single Line Comments Eg : //
– Multi Line comments Eg : /* */
– XML Documentation Comments Eg : ///
12. What are the predefined typed in C# ?
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.
13. What are the primitive types in CLR ?
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.
14. What are the various suffixes used for Numeric types in C# ?
F – float
D – double
M – decimal
U – uint
L – long
UL – ulong
15. What is the output of the following code ?
int Input1 = 100000001;
float Float1 = Input1;
int Output1 = (int)Float1;
Console.WriteLine(Output1);
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 .
16. How to make sure that the arithmetic overflow exception when it happens in C# ?
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.
17. Which are the operator where the checked operator or block doesnot have have any effect on ?
The checked operator does not have any effect on the following datatypes – double , float , decimal.
18. What are the various special values supported by float and double in C# ?
double.NaN , float.NaN
double.PositiveInfinity , float.PositiveInfinity
double.NegativeInfinity , float.NegativeInfinity
?0.0 , ?0.0f
19. When does the floating value division results in a Infinite value in C# ?
When the floating point number is divided by zero , this results in the infinity value.
Console.WriteLine ( 5.0 / 0.0);
20. When does the result of an operation will be Nan in C# ?
The result will be Nan when we try to divide zero by zero or subtract infinity from infinity.
Console.WriteLine ( 0.0 / 0.0);
Leave a Reply