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
are the types of comment in C#?
Single line,Multi line,XML document
3. What is
the difference between public, static and void?
Public declared variables or methods are accessible anywhere
in the application. Static declared variables or methods are globally
accessible without creating an instance of the class. The compiler stores the
address of the method as the entry point and uses this information to begin
execution before any objects are created. And Void is a type modifier that
states that the method or variable does not return any value.
4. What is
an Object?
An object is an instance of a class through which we access the methods of that
class. “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.
5. Define
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.
6. 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.
7. 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.
8. 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.
9. 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 .
10. What
is the difference between a Struct and a Class?
Structs are value-type variables and classes are reference types. Structs
stored on the stack, causes additional overhead but faster retrieval. Structs
cannot be inherited.
11. 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
12. Is C#
code is managed or unmanaged code?
C# is managed code because Common language runtime can compile C# code to
Intermediate language.
13. What
is static constructor?
Static constructor is 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 that class with keyword. A static constructor does not
take access modifiers or have parameters and can’t access any non-static data
member of a class.
14.What is
an Array?
An array is a collection of related instance either value or reference types.
Array posses an immutable structure in which the number of dimensions and size
of the array are fixed at instantiation.
C# Supports Single, Mult dimensional and Jagged Array.
Single Dimensional Array: it is sometimes called vector array consists of
single row.
Multi-Dimensional Array: are rectangular & consists of rows and columns.
Jagged Array: also consists of rows & columns but in irregular shaped (like
row 1 has 3 column and row 2 has 5 column)
15. What
is an ArrayList?
ArrayList is a dynamic array. Elements can be added & removed from an
arraylist at the runtime. In this elements are not automatically sorted.
16. What
is BitArray?
The BitArray collection is a composite of bit values. It stores 1 or 0 where 1
is true and 0 is false. This collection provides an efficient means of storing
and retrieving bit values.
17. What
is HashTable?
A Hashtable is a collection of key-value pairs. Entries in this are instance of
DictionaryEntry type. It implements IDictionary, ISerilizable, IDeserializable
collback interface.
18. What
is Queue?
This is a collection that abstracts FIFO (First In First Out) data structure.
The initial capacity is 32 elements. It is ideal for messaging components.
19. What is Stack?
This is a collection that abstracts LIFO (Last In First Out) data structure in
which initial capacity is 32.
20. What
is a collection?
A collection serves as a container for instances of other classes. All classes
implement ICollection interface which intern implement IEnumerable interface.
21. What
is reflection?
Reflection is the ability to find the information about types contained in an
assembly at runtime.
22. How
can you sort the elements of the array in descending order?
By calling Array.Sort() and then Array.Reverse() methods.
23. What
class is underneath the SortedList class?
A sorted HashTable.
24. Can
you prevent your class from being inherited by another class?
Yes. The keyword “sealed” will prevent the class from being inherited.
25. Can
you allow a class to be inherited, but prevent the method from being
over-ridden?
Yes. Just leave the class public and make the method sealed.
26. What are the different ways a method can be overloaded?
Different parameter data types, different number of parameters, different order
of parameters.
27.
Difference between classes and structures?
A struct is a value type and a class is a reference type.
When we instantiate a class, memory will be allocated on the heap and when
struct gets initiated it gets memory on the stack.
Classes can have explicit parameter less constructors. But structs dosn’t
have this.
Classes support inheritance. No inheritance for structs.
A struct cannot inherit from another struct or class, and it cannot be the
base of a class. Like classes, structures can implement interfaces.
28. What is
Jagged Arrays?
The array which has elements of type array is called jagged array. The elements
can be of different dimensions and sizes. We can also call jagged array as
Array of arrays.
29. What is
the difference between ref & out parameters?
An argument passed as ref must be initialized before passing to the method
whereas out parameter needs not to be initialized before passing to a method.
30. 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.
30. What is serialization?
When we want to transport an object through network then we have to convert the
object into a stream of bytes. The process of converting an object into a
stream of bytes is called Serialization.