1. What is C#?
C# is an object oriented type safe and managed language that is
compiled by .Net framework to generate Microsoft Intermediate
Language.
2. What is a Class?
a set or category of things having some
property or attribute in common and differentiated from others by kind, type,
or quality.
3. What is an object?
An object is an instance of a class through
which we access the methods of that class. In C# “New” keyword is used to
create an object. A class that creates an object in memory will contain the
information about the methods, variables and behavior of that class.
4. What is Constructors?
A constructor is a member function in a class
that has the same name as its class. The constructor is automatically invoked
whenever an object class is created. It constructs the values of data members
while initializing the class.
5. What is the use of using statement in C#?
The using block is used to obtain a resource
and use it and then automatically dispose of when the execution of block
completed.
6. What is an interface class?
Interface is an abstract class which has only public abstract
methods and the methods only have the declaration and not the definition. These
abstract methods must be implemented in the inherited classes.
7. What are value types and reference
types?
Value types are stored in the Stack.
e.g:- int, enum , byte, decimal, double, float, long
Reference types stored on heap.
e.g:- string, class, interface, object
8. What are sealed classes in C#?
We create sealed classes when we want to restrict the class to
be inherited. Sealed modifier used to prevent derivation from a class. If we
forcefully specify a sealed class as base class then a compile-time error
occurs.
9. What’s
the difference between an interface and abstract class?
Interfaces have all the methods having only declaration but no
definition. In an abstract class, we can have some concrete methods. In an
interface class, all the methods are public. An abstract class may have private
methods.
10.What is the difference
between Finalize() and Dispose() methods?
Dispose() is called when we want for an object to release any
unmanaged resources with them. On the other hand Finalize() is used for the
same purpose but it doesn’t assure the garbage collection of an object.
11. What are generics in C#.NET?
Generics are used to make reusable code classes to decrease the
code redundancy, increase type safety and performance. Using generics, we can
create collection classes. To create generic collection, System.Collections.Generic
namespace should be used instead of classes such as ArrayList in the
System.Collections namespace. Generics promotes the usage of parameterized
types.
12. What are delegates?
Delegates are same are function pointers in C++ but the only
difference is that they are type safe unlike function pointers. Delegates are
required because they can be used to write much more generic type safe
functions.
14. What is the difference
between method overriding and method overloading?
In method overriding, we change the method definition in the
derived class that changes the method behavior. Method overloading is creating
a method with the same name within the same class having different signatures.
15. What
are the different ways a method can be overloaded?
Methods can be overloaded using different data types for
parameter, different order of parameters, and different number of parameters.
16. What are indexers in C# .NET?
Indexers are known as smart arrays in C#. It allows the
instances of a class to be indexed in the same way as array.
e.g.:- public int this[int index] // Indexer declaration
17. What is difference between the “throw” and “throw ex” in .NET?
“Throw” statement preserves original error stack whereas “throw
ex” have the stack trace from their throw point. It is always advised to use
“throw” because it provides more accurate error information.
18. How to implement singleton
design pattern in C#?
In singleton pattern, a class can only have one instance and
provides access point to it globally.
e.g:- Public sealed class Singleton
{
Private static readonly Singleton _objSingleton = new Singleton();
}
19. Explain use of Abstract and Sealed Classes in C#?
The abstract keyword enables you to create classes
and class members that are incomplete and must be implemented in a derived
class.
The sealed keyword enables you to prevent the
inheritance of a class or certain class members that were previously marked
virtual.
20. Which
are Access Modifiers available in C#?
All types and type members have an accessibility
level, which controls whether they can be used from other code in your assembly
or other assemblies.
You can use the following access modifiers to
specify the accessibility of a type or member when you declare it:
public: The
type or member can be accessed by any other code in the same assembly or
another assembly that references it.
private: The
type or member can be accessed only by code in the same class or struct.
protected: The type or member can be accessed only by code in the
same class or struct, or in a class that is derived from that class.
internal: The
type or member can be accessed by any code in the same assembly, but not from
another assembly.
21. Data Types in C#?
bool, byte , char,
decimal , double, float, int, long, sbyte , short,
uint, ulong, ushort.