Sei sulla pagina 1di 5

Explain sealed class in C#?

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.

Below is the sample code of sealed class in C# -

class X {}

sealed class Y : X {}

Sealed methods –

class A

protected virtual void First() { }

protected virtual void Second() { }

class B : A

sealed protected override void First() {}

protected override void Second() { }

8) List out the differences between Array and ArrayList in C#?

 Array stores the values or elements of same data type but arraylist stores values of
different datatypes.
 Arrays will use the fixed length but arraylist does not uses fixed length like array.

Why to use “using” in C#?

“Using” statement calls – “dispose” method internally, whenever any exception


occurred in any method call and in “Using” statement objects are read only and cannot
be reassignable or modifiable.
13) Explain “static” keyword in C#?

“Static” keyword can be used for declaring a static member. If the class is made static then
all the members of the class are also made static. If the variable is made static then it will
have a single instance and the value change is updated in this instance.

30) Can we override private virtual method in C#?

No. We can’t override private virtual methods as it is not accessible outside the class.

48) What is Nullable Types in C#?


Variable types does not hold null values so to hold the null values we have to use nullable
types. So nullable types can have values either null or other values as well.

54) Why to use lock statement in C#?

Lock will make sure one thread will not intercept the other thread which is running the part
of code. So lock statement will make the thread wait, block till the object is being released.

82) Explain Overloading in C# ?

When methods are created with the same name, but with different signature its called
overloading. For example, WriteLine method in console class is an example of overloading.
In the first instance, it takes one variable. In the second instance, “WriteLine” method takes
two variable.

Console.WriteLine(x);

Console.WriteLine("The message is {0}", Message);

88) Can Multiple Inheritance implemented in C# ?

In C#, derived classes can inherit from one base class only. If you want to inherit from
multiple base classes, use interface.

89) What is Polymorphism in C# ?

The ability of a programming language to process objects in different ways depending on


their data type or class is known as Polymorphism. There are two types of polymorphism

 Compile time polymorphism. Best example is Overloading


 Runtime polymorphism. Best example is Overriding

90) Explain the use of Virtual Keyword in C# ?


When we want to give permission to a derived class to override a method in base class,
Virtual keyword is used. For example. lets us look at the classes Car and Ford as shown
below.

class Car

public Car()

Console.WriteLine("Base Class Car");

public virtual void DriveType()

Console.WriteLine("Right Hand Drive");

class Ford : Car

public Ford()

Console.WriteLine("Derived Class Ford");

public void Price()


{

Console.WriteLine("Ford Price : 100K $");

public override void DriveType()

Console.WriteLine("Right Hand ");

91) What is overriding in c# ?

To override a base class method which is defined as virtual, Override keyword is used. In
the above example, method DriveType is overridden in the derived class.

32. What is MVC?

MVC is a framework used to create web applications. The web application base builds
on Model-View-Controller pattern which separates the application logic from UI, and the input
and events from the user will be controlled by the Controller.

36. How do you register JavaScript for webcontrols ?


We can register javascript for controls using <CONTROL -
name>Attribtues.Add(scriptname,scripttext) method.

The short answer would be: in the Stack are stored value types (types
inherited from System.ValueType ), and in the Heap are stored reference
types (types inherited from System.Object ).
We can say the Stack is responsible for keeping track of what is actually
executing and where each executing thread is (each thread has its own
Stack). The Heap, on the other hand, is responsible for keeping track of
the data, or more precise objects.

What is the difference between an abstract class and an interface?


An abstract class is always used as a base class. It provides some abstract/virtual
members that the inheriting entities must implement, as well as a partial implementation
for a functionality. For extra credit during a .NET interview, your candidate might mention
that this class can also declare fields. Developers cannot create an object from this class.

An interface, on the other hand, can declare properties, methods and events only (no
access modifiers). The developer must implement all declared members. In short, an
interface designates a contract/behavior that implementing classes should have.

When should you use .NET Web Forms over ASP.NET MVC?
Traditionally, the .NET framework has been based on web forms. This was essentially an
effort to create web services using Microsoft’s existing Visual tools without forcing
developers to learn new scripting languages. Web Forms still allows developers to create
quick and simple applications, and some legacy systems may still run as Web Forms.

ASP.NET MVC is increasingly the standard for contemporary developers, however. In


a .NET interview, a strong candidate should be able to highlight the advantages of the
Model-View-Controller architectural pattern. MVC’s most important feature is that it allows
applications to be broken down into discrete models, views and controllers, making them
much easier to test during development.

Potrebbero piacerti anche