*
Previous C# Question Answers-61 - 70 C# Question Answers-81 - 90 Next

C# (C-Sharp) Question Answers - 71-80

71. What is Covariance and Contravariance?

Covariance: Substitute a derived type where a base type is expected. Contravariance: Substitute a base type where a derived type is expected. Supported only for reference types.

72. What is Data Abstraction?

Data abstraction is a simplified view of an object showing only essential features and hiding unnecessary details. In OOP, implemented as a class or abstract data type.

73. What is difference Hashtable and Dictionary?

  • Hashtable and Dictionary store key-value pairs.
  • Hashtable is thread-safe; Dictionary is not.
  • Dictionary is generic; no boxing/unboxing needed. Hashtable requires boxing/unboxing.
  • Dictionary throws KeyNotFoundException for missing keys; Hashtable returns null.
  • Dictionary maintains insertion order; Hashtable does not.
  • Dictionary uses chaining; Hashtable uses rehashing.
  • Hashtable is weakly typed; Dictionary is strongly typed.

74. What is Dynamic Polymorphism?

Occurs when using virtual in base class and override in derived class.

75. What is Encapsulation?

Encapsulation is the mechanism of bundling code and data into a single unit and protecting it from external interference. Implemented using classes in C#.

76. What is explicit and implicit interface and when should we use?

Explicit: Implement interface members with interface name. Implicit: Implement interface members without interface name. Use implicit normally; use explicit when implementing multiple interfaces with conflicting method signatures.

77. What is Extension method?

An extension method is a static method of a static class that can be invoked like as an instance method syntax. Extension methods are used to add new "Behaviors" to an existing type without altering.

In extension method this keyword is used with the first parameter and the first parameter will be of type that is extended by extension method. Other parameters of extensions types can be of any types (data type).

A static method of a static class that can be called as if it were an instance method.

public static class MyExtensions {
  public static int Square(this int n) { return n * n; }
}

int m = 5;
Console.WriteLine("{0} is square of {1}", m.Square(), m);
// Output: 25 is square of 5

78. What is full Garbage Collection?

Gen-2 collection is called Full Garbage Collection. It collects all objects from Gen-0, Gen-1, and Gen-2.

79. What is Full Trust? Do GAC’ed assemblies have Full Trust?

Full Trust allows code to have all permissions. GAC’ed assemblies have Full Trust by default due to being on the local system with a strong name.

80. What is gacutil?

Global Assembly Cache Tool (gacutil.exe) allows installing, removing, and listing assemblies in the GAC.

Back to Index
Previous C# Question Answers-61 - 70 C# Question Answers-81 - 90 Next
*
*