Generic Interface Demo : Generic Interface : Generics C# Source Code


Custom Search

C# Source Code » Generics » Generic Interface »

 

Generic Interface Demo








    
 
using System;
using System.Collections.Generic;
using System.Text;

class Program {
    static void Main(string[] args) {
        Console.WriteLine("Generic Interfaces");

        BasicMath m = new BasicMath();
        Console.WriteLine("1 + 1 = {0}", m.Add(1, 1));
        Console.ReadLine();
    }
}
public interface IBinaryOperations<T> {
    T Add(T arg1, T arg2);
    T Subtract(T arg1, T arg2);
    T Multiply(T arg1, T arg2);
    T Divide(T arg1, T arg2);
}

public class BasicMath : IBinaryOperations<int> {
    public int Add(int arg1, int arg2) { return arg1 + arg2; }

    public int Subtract(int arg1, int arg2) { return arg1 - arg2; }

    public int Multiply(int arg1, int arg2) { return arg1 * arg2; }

    public int Divide(int arg1, int arg2) { return arg1 / arg2; }


}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Generics
» Generic Interface