TEST INTERVIEW
1.
What is a variable?
A
variable is
a name given to a memory location and all the operations done on the
variable effects that memory location
. In C#, all the variables must be declared
before they can be used. It is the basic unit of storage in a program. The value stored
in a variable can be changed during program execution.
2.
What is value type and reference type? Difference between them?
A Value Type holds the data within its own memory allocation and a
Reference Type
contains a pointer to another memory location that holds the real data
. Reference
Type variables are stored in the heap while Value Type variables are stored in the
stack.
3.
What is boxing and unboxing?
Boxing is a process that converts from value type to reference type, unboxing is
opposite process which means converts from reference type to value type.
4.
What is checked and unchecked?
C# statements can execute in either checked or unchecked context. In a checked
context,
arithmetic overflow raises an exception
. In an unchecked context,
arithmetic overflow is ignored and the result is truncated by discarding any high-
order bits that don't fit in the destination type.
5.
Dynamic and static array declaration?
There are 2 methods commonly used for declaring arrays. While both have their
place and usage, most programmers prefer the dynamic array
that is declared at run-
time to provide the most flexibility. The static array is great if you have a set
structure that will never change.
For instance, an array that holds the days of the
week, months
in the year, or even the colors in a rainbow. These won't change and
they won't be data driven so in this case, a static array will be best.
6.
How can we make a variable store different types of data?
~~
7.
What is implicit type?
Implicitly typed variables are those variables which are declared without specifying
the exact type In implicitly typed variable, the type of the variable is
automatically
deduced at compile time by the compiler from the value used to initialize the
variable.
8.
What is a nullable type?
In C#, you can assign the null value to any reference variable.
The null value simply
means that the variable does not refer to an object in memory.
9.
What types can I use in foreach?
It just sets up a variable that is set to each value in the array successively. To set up a
for-each loop, use for (