CSharp Basic Questions and Answers

What values can a bool type have?
True or False.

What is the difference between an int and an Int32?
int is the C# alias for the .NET Int32 type. They can be used interchangeably.

Which of the following code statements will compile?
int myInt = 25;
long myLong = myInt;
int newInt = myLong;
All except the last, which requires an explicit cast:
int newInt = (int) myLong;

What is the difference between an int and a uint?
A uint is an unsigned int and can hold only positive numbers, but it can hold a positive value twice as big as an int (4 million+ rather than 2 million+).

What is the difference between a float and a double?
A float takes four bytes and a double takes eight bytes, and thus a double can represent much larger values with greater precision.

Explain definite assignment.
In C, if you wish to use a variable of any type (pass it as a parameter to a method), you must assign it a value.

Given the following declaration, how would you refer to the constant for LightJacketWeather and what would its value be?

enum Temperatures
WickedCold = 0,
FreezingPoint = 32,
SwimmingWeather = 72,
BoilingPoint = 212,

You refer to the constant like this:

What is an expression?
Any statement that evaluates to a value.

No comments: