Vous êtes sur la page 1sur 2

1. What are Static constructors? Their use and features.

a. C3 supports two types of Constructors Class Constructors(static Constructors) and


Instance Constructors(non static Constructors)
b. Static Constructors are used to initialize static data members as soon as the class is
referenced first time whereas an instance constructor is used to create an instance of
the class with new keyword.
c. Static constructor does not take any access modifier, no parameters and can access
only the static members.
d. Main use of static constructor is to initialize static data members. We may say that
static data members may be initialized at the time of declaration itself like
private static int i = 10;
private static string abc =Nidhi;
But static constructor comes handy if we want to do conditional initialization of static
data members.
e. Main features of static constructors:i. Static Constructor of a class executes before any instance of the class is created.
ii. Static Constructor of a class executes before any static data members of the
class are referenced.
iii. SC runs at most one time during the execution of the program.
iv. SC cannot be called directly.
2. Difference between String Builder and String class?
Strings are immutable so each time they are operated on a new instance is created
while String Builder are mutable that is when they are operated on same instance is
being used.
3. What are generics and their advantages.
Generic classes and methods combine reusability, type safety and efficiency in a way that their
non generic counter parts cannot. Generics are most commonly used with collections and
methods that operate on them.
Generics provide a solution to the limitation of the earlier versions of CLR and C# where
generalization is accomplished by casting types to and from the universal base type object.
Generic collections are type safe at compile time and do not require boxing unboxing hence are
more efficient than their non generic counter parts.
ArrayList and List<T> :- ArrayList is non generic but List<T> is generic .

4. What are Nullable types in C#?

5.

Vous aimerez peut-être aussi