1
Reply

generics

kamal

kamal

Sep 16 2010 4:01 PM
2.3k
how to add two integer and float variables?

class genericclass<T>
    {
      

        private T a;
        private T b;

        public void sum(T val1, T val2)

        {
            Console.WriteLine(" sum is "+ (val1 + val2));
        }
   
 
    }

    class Program
    {
        static void Main(string[] args)
        {

            genericclass<int> gcint1= new genericclass<int>;
            gcint1.sum(2, 3);
            genericclass<float> gcfloat1=new genericclass<float>;
            gcfloat1.sum(2.0, 3.0);


        }
    }

Answers (1)