1
Answer

generics

kamal

kamal

14y
2.7k
1
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)