About me

Tuesday, September 29, 2015

Best C# Language Interview Questions and Answers


16. Can you declare an overridden method to be static if the original method is not static?

 No. Two virtual methods must have the same signature.

17. Why is the virtual keyword used in code?

The virtual keyword is used while defining a class to specify that the methods and the properties of that class can be overridden in derived classes.


18. Can you allow a class to be inherited, but prevent a method from being overridden in C#?

Yes. Just declare the class public and make the method sealed .

 19. Define enumeration?

Enumeration is considered as a value type that contains of a set of named values. These values are constants and are called enumerators. An enumeration type is declared which uses the enum keyword. Each enumerator in an enumeration is associated with an underlying type that is set, by default, on the enumerator. The following is an example that creates an enumeration to store different varieties of fruits:

 enum Fruits {Mango, Apple, orange, Guava};

 In the preceding example, an enumeration Fruits is created, where number 0 is associated with Mango, number 1with Apple, number 2 with Orange, and number 3 with Guava. You can access the enumerators of an enumeration by these values.

20. In which namespace, all .NET collection classes are contained?

 The System.Collections namespace contains all the collection classes.


No comments:

Post a Comment