C Sharp Interview Questions and Answer
1. C-Sharp (C#)
C# is a type-safe, managed and object oriented language, which is compiled by .Net framework for
generating intermediate language (IL)
2. Types of comments in C#
Below are the types of comments in C# -
Single Line Comment Eg : //
Multiline Comments Eg: /* */
XML Comments Eg : ///
3. Sealed class and Sealed method in C#
Sealed Methods
Sealed method is used to define the overriding level of a virtual method.
Sealed keyword is always used with override keyword.
So “sealed” modifier also can be used with methods to avoid the methods to override in the child
classes.
class Program
{
public class BaseClass
{
public virtual void Display()
{
Console.WriteLine("Virtual method");
}
}
public class DerivedClass : BaseClass
{
// Now the display method have been sealed and can;t be
overridden
public override sealed void Display()
{
Console.WriteLine("Sealed method");
}
}
//public class ThirdClass : DerivedClass
//{
// public override void Display()
// {
// Console.WriteLine("Here we try again to override display
method which is not possible and will give error");
// }
//}
Sealed class is used to prevent the class from being inherited from other classes. So “sealed” modifier
also can be used with methods to avoid the methods to override in the child classes.