kamal

kamal

  • NA
  • 1
  • 2.6k

generics

Sep 16 2010 4:01 PM
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)