Thursday, March 1, 2012

Generic function call


 public class clsGeneric
    {
        public void show<T>(T value)
        {
            Type t = typeof(T);
            Console.WriteLine(t.Name + ":" + value);
        }
    }


 class Program
    {
         static void Main(string[] args)
        {
             clsGeneric ng;
            ng = new  clsGeneric();
            int a = 10;
            ng.show(a);
            string b = "SS";
            ng.show(b);

            Console.WriteLine("Press any key to close........");
            Console.ReadKey();
        }
    }

OUTPUT
----------------------------
Int32:10
String:SS
Press any key to close........



use global variable with same name of Local variable


 public class Demo1
    {
        int a = 10;
        public  void ff()
        {
            int a = 11;
            Console.WriteLine("a={0}", this.a);
        }


   class Program
    {
        static void Main(string[] args)
        {
              Demo1 ng = new   Demo1();
             ng.ff();

            Console.WriteLine("Press any key to close........");
            Console.ReadKey();

        }
}


Output:
-----------------------------------
a=10
Press any key to close........
-----------------------------------

Hash Table in C#

 The Hashtable is a non-generic collection and used to store the key/value pairs based on the hash code of the key. Key will be used to acce...