.Net Interview Day - 10

October 12, 2017 0 Comments A+ a-

1) What are generics in c#.net?

Generics allow you to delay the specification of the data type of programming elements in a class or a method, until it is actually used in the program.
The classes and the methods can treat the values of different types uniformly with the use if generics.

2)What are advantages of generics in c#.net?

Please follow the below points
  • It facilitate type safety, maximize code reuse and performance.
  • They promote the usage of parameterized types.
  • It can allow to create your own generic classes, delegates, methods, events and interfaces.
  • The CLR compiles and stores information related to the generic types when they are instantiated.

3)What is Hashtable in C#?

  • Hashtable collection in System.Collections namespace, and It is similar to generic dictionary collection.
  • It is used to store the key-value pairs based on hash code of the key.
  • Key will be used to access the element in the collection.
Ex:-
Hashtable hasTbl = new Hashtable();
hasTbl.Add("1", "TutorialsLife");

4)What is dictionary in C#?

  • A Dictionary class is a data structure that represents a collection of keys and values pair of data.
  • The key is identical in a key-value pair and it can have at most one value in the dictionary, but a value can be associated with many different keys.
  • Dictionary is a generic collection included in the System.Collection.Generics namespace. 
  • TKey denotes the type of key and TValue is the type of TValue.

5) What are the differences Between Hashtable and Dictionary ?

Hashtable:-
  • Hashtable is threadsafe
  • It does not allow the order of records at retrieve time.
  • Hashtable is not a generic type
  • It is slower than dictionary because it requires boxing and unboxing.
Dictionary:- 
  • Dictionary is not threadsafe
  • It allow the order of records at retrieve time.
  • Dictionary is a generic type which means we can use it with any data type.
  • It is faster than a Hashtable because there is no boxing and unboxing.

6) How to check whether hash table contains specific key in C#?

"ContainsKey" method can be used to check the key in hash table.

7)What is list in c# ?

The List class in .NET represents a strongly typed list of objects that can be accessed by index.
List class is a collection and defined in the System.Collections.Generic namespace and hence provides most of the collections related built-in methods and properties including add, remove, search, and sort.

8) What are the differences Between List and Dictionary?

List:- 
  • List is a collection which is used with collection of items like Array etc.
  • List allow fast access by index
  • It is inheritance from ICollection interface.
Dictionary:-
  • Dictionary is a pair of key and value
  • Dictionary allow slow access as compare to List.
  • It is inheritance from IDictionary interface.

9) What is Reflection in C#.Net?

Reflection typically is the process of runtime type discovery to inspect metadata, CIL code, late binding and self-generating code.
At run time by using reflection, we can access the same "type" information as displayed by the ildasm utility at design time.
The reflection is analogous to reverse engineering in which we can break an existing *.exe or *.dll assembly to explore defined significant contents information, including methods, fields, events and properties.

10) What is Serialization?

Serialization is the process of converting complex objects into stream of bytes for storage.
The namespace which is used to read and write files is System.IO. For Serialization we are going to look at the System.Runtime.Serialization namespace. The ISerializable interface allows you to make any class Serializable.