Generics example in c sharp — C Sharp — ASP.Net Example
ASP.Net Example-Generics example in c sharp

Saturday, April 23, 2011

Generics example in c sharp

Generics is belongs from System.Collections.Generic class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Generics
{
    public class Test
    {
        public T EmpID
        {
            set;
            get;
        }

        public void show(T t,N n)
        {
            if (typeof(T) == typeof(int) && typeof(N) == typeof(int))
            {
                int x = Convert.ToInt32(t);
                int y = Convert.ToInt32(n);
                Console.WriteLine(x + y);
            }
            else if (typeof(T) == typeof(string) && typeof(N) == typeof(int))
            {
                Console.WriteLine("The " + t + "'s Age is " + n);
            }

        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Test ob = new Test();
            ob.EmpID = 10;
            ob.show(10, 20);

            Test ob1 = new Test();                        
            ob1.show("Rajesh",20);
        }
    }
}

No comments:

Post a Comment

ASPdotNET-Example