C# and .NET interview questions .NET
1.How big is the datatype int in .NET? 32 bits.
2.How big is the char? 16 bits (Unicode).
3.How do you initiate a string without escaping each backslash? Put an @ sign in front of the
4.What are valid signatures for the Main function?
lpublic static void Main()
lpublic static int Main()
lpublic static void Main( string args )
lpublic static int Main(string args )
5.How do you initialize a two-dimensional array that you don\u2019t know the dimensions of?
lint [, ] myArray; //declaration
lmyArray= new int [5, 8]; //actualinitialization
6.What\u2019s the access level of the visibility type internal? Current assembly.
7.What\u2019s the difference between struct and class in C#?
lStructscannot be inherited.
lStructsare passed by value, not by reference.
lStruct is stored on the stack, not the heap.
8.Explain encapsulation. The implementation is hidden, the interface is exposed.
9.What data type should you use if you want an 8-bit value that\u2019s signed?sb yte.
10.Speaking of Boolean data types, what\u2019s different between C# and C/C++? There\u2019s no
conversion between 0 and false, as well as any other number and true, like in C/C++.
11.Where are the value-type variables allocated in the computer RAM?Stack.
12.Where do the reference-type variables go in the RAM? The references go on the stack, while
the objects themselves go on the heap.
13.What is the difference between the value-type variables and reference-type variables in
terms of garbage collection? The value-type variables are not garbage-collected, they just fall off the
stack when they fall out of scope, the reference-type objects are picked up by GC when their
references go null.
14.How do you convert a string into an integer in .NET?Int32.Pa rse(strin g)
15.How do you box a primitive data type variable? Assign it to the object, pass an object.
16.Why do you need to box a primitive variable? To pass it by reference.
17.What\u2019s the difference between Java and .NET garbage collectors? Sun left the implementation
of a specific garbage collector up to the JRE developer, so their performance varies widely, depending
on whose JRE you\u2019re using. Microsoft standardized on their garbage collection.
18.How do you enforce garbage collection in .NET?S ystem.GC.Col le ct();
19.Can you declare a C++ type destructor in C# like ~MyClass()? Yes, but what\u2019s the point, since
it will call Finalize(), and Finalize() has no guarantees when the memory will be cleaned up, plus, it
introduces additional load on the garbage collector.
20.What\u2019s different about namespace declaration when comparing that to package declaration
in Java? No semicolon.
21.What\u2019s the difference between const and readonly? You can initialize readonly variables to
some runtime values. Let\u2019s say your program uses current date and time as one of the values that
won\u2019t change. This way you declare public readonly string DateT = new DateTime().ToString().
22.What does \a character do? On most systems, produces a rather annoying beep.
23.Can you create enumerated data types in C#?Ye s .