Sunday 29 January 2017

C# basic interview questions Part-1

1. Ques: What are the version numbers of C# ? 
Answer:


Version
.NET Framework
C# 1.0
.NET Framework 1.0/1.1
C# 2.0
.NET Framework 2.0
C# 3.0
.NET Framework 3.0\3.5
C# 4.0
.NET Framework 4.0
C# 5.0
.NET Framework 4.5
C# 6.0
.NET Framework 4.6


2. Ques: What is difference between Dictionary & Hashtable ?
Answer:
Dictionary:
1.Dictionary is generic type.
2.Returns an error if the key does not exist.
3.No boxing and unboxing.
4.Faster than a Hash table.
5.dictionary is not tread safe.

Hashtable:
1.Hashtable is not generic type.
2.Returns NULL even if the key does not exist.
3.Requires boxing and unboxing.
4.Slower than a Dictionary.
5.hash table is not a generic type.
6.hash table is tread safe.


3. Ques: What is Reflection in dot net? 
Answer:
  • Reflection used for obtaining type information of assembly at runtime. 
  • It Load assemblies at runtime and give the information of field,properties, constructors, event and methods of class.
  • It is a collection of classes which allow u to query assembly (class/object) metadata at runtime.
  • Using reflection we can also create new types and their instances at runtime and invoke methods on these new instances.
  • At runtime, the Reflection mechanism uses the PE file to read information about the assembly.
  • We can dynamically invoke methods using System.Type.Invokemember
  • We can dynamically create types at runtime using System.Reflection.Emit.TypeBuilder
  • Reflection objects are used for obtaining type information at runtime. 
  • The classes belong to the System.Reflection namespace.
With reflection we can do the below task

  • we can dynamically create an instance of a type
  • bind the type to an existing object
  • get the type from an existing object
  • invoke its methods or access its fields and properties



4. Ques: What are Assemblies?
Answer:
Assembly is the smallest unit of deployment of a .net application. 
It can be either dll or an exe.

5. Ques: How many type of assembly are in .net framework?
Answer:
There are three type of assembly in .net framework?
Private: It is stored in the application's directory. 
Shared : It is stored in GAC (Global Assembly Cache).
Satelite : It is stored in specific application's directory.


6. Ques: What is array?
Answer:
  • Array as a collection of variables of the same type of fixed-size. 
  • Array are reference types.
  • array strongly type of collection.
  • arrays belong to "System.Array" namespace

ex:  int[] arr = new int[10];
       string[] arr = new string[10];
       bool[] arr = new bool[2];



7. Ques:What are different type of array in c#?
Answer : Three types  of array in C#:
Single Dimensional Array: It contains a single row. It is also known as vector array.
Multi Dimensional Array: It is rectangular and contains rows and columns.
Jagged Array: In Jagged Array the element is itself is array. It also contains rows and columns but it has an irregular shape.


8. Ques: How to create jagged arrays in c#?
Answer :
int[][] jagrray= new int[4][];
jagrray [0] = new int[5];
jagrray[1] = new int[3];
jagrray[2] = new int[2];
jagrray[3] = new int[1];

for (int i = 0; i < jagrray.Length; i++)
    {
        int[] innerArray = jagrray[i];
        for (int j = 0; j < innerArray.Length; j++)
        {
            Console.Write(innerArray[j] + " ");
        }
        Console.WriteLine();
    }


9. Ques: What is Arraylist?
Answer:
  • Arraylist collection of variables of same or different datatypes. 
  • Arraylist class found in "System.Collections” namespace.
  • Size of arraylist object will increase or decrease dynamically.
  • Arraylist very flexible because we can add & delete without any size information.
  • Arraylist not a strongly type of collection. 

10. Ques: What is a collection.how many types of collection in C#?
Answer:
Collections are data structures that holds data or objects in memory.
list of collection which supported by C# given bellow.
ArrayList
HashTable
SortedList
BitArray
Queue
Stack




No comments:

Post a Comment

Thank you for comment