C# Generics

Generics Class:

using System;
namespace GenericsClass
{
    class GenericClass<T>
    {
        public GenericClass(T msg)
        {
            Console.WriteLine(msg);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {


            GenericClass<string> gen=new GenericClass<string>("This is generic class");
            GenericClass<int> inrr=new GenericClass<int>(101);
            GenericClass<char> getCh=new GenericClass<char>('I');

            Console.ReadKey();
        }
    }
}

 

 

Generics method:

using System;

namespace GenericMEthod
{
    class GenericClass
    {
        public void Show<T>(T msg)
        {
            Console.WriteLine(msg);
        }

    }
    class Program
    {
        static void Main(string[] args)
        {
            GenericClass genc=new GenericClass();
            genc.Show("This is generic method");
            genc.Show(101);
            genc.Show('I');
            Console.ReadKey();
        }
    }
}

 

 

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.