What is the difference between Hash Table and Dictionary?

The Dictionary(Of TKey, TValue) and ConcurrentDictionary(Of TKey, TValue)classes have the same functionality as the Hashtable class. A Dictionary(Of TKey, TValue) of a specific type (other than Object) provides better performance than a Hashtable for value types. This is because the elements of Hashtable are of type Object; therefore, boxing and unboxing typically occur when you store or retrieve a value type.

    //Type casting is required

    Hashtable ht = new Hashtable();

    ht.Add(1, 2);// it allows any type of value (object)

    ht.Add(2,"A");

 

    //No need type casting, because it is strongly typed

    Dictionary<int, string> d = new Dictionary<int, string>();

    d.Add(1, "yusyu"); // it allows only specific type

    d.Add(4, 77); // it throws error

What is the difference between Class variable and Instance Variable?

Instance variables have separate values for each instance of a class. Class variables maintain a single shared value for all instances of the class, even if no instance object of that class exists.

You would use the static keyword to change an instance variable into a class variable.

Both instance and class variables are declared at the class level, not within methods:

public class Cherukuri

{

    static private int count; // class variable

    String name; // instance variable

    private void Bar()

    {

        int halfCount; // local variable

    }

}

Note also that classes are loaded by classloaders therefore class variables are unique on a per-classloader basis.

What is  the difference between application variables and Session variables?

Application Variables are actually global variables for each application..you can share these variables through out the applications..the life time of the application variables span thro the life time of the application until the application is unloaded..

And the session variables are used to store the User based unique values..and you can set the time limit to store the values in the session state variables..

Application variables are values that are available to any user or page within an application.

Session Variables are values that are available to one user.

What is the disadvantage of using the Singleton pattern?

What is the difference between Class and Partial Class?

What is the difference between Method and Partial Method?

What is the difference between a field and a property in C#?

Properties expose fields. Fields should (almost always) be kept private to a class and accessed via get and set properties. Properties provide a level of abstraction allowing you to change the fields while not affecting the external way they are accessed by the things that use your class.

public class MyClass {
   
// this is a field.  It is private to your class and stores the actual data.
   
private string _myField;

   
// this is a property.  When you access it uses the underlying field, but only exposes
   
// the contract that will not be affected by the underlying field
   
public string MyField {
     
get {
       
return _myField;
     
}
     
set {
       _myField
= value;
     
}
   
}
}