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........



No comments:

Post a Comment

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...