C# 泛型里使用四则运算的办法,委托的妙用
直接上代码
public static class TestGenricCalc { public static T Clac<T>(T t1, T t2,Func<T,T,T>func) where T : struct { return func(t1, t2); } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); var c=TestGenricCalc.Clac<float>(1, 2, (a, b) => { return a + b; }); Console.WriteLine(c); Console.ReadKey(); }
结果:


浙公网安备 33010602011771号