直接上代码
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(); }
结果:
标签:Console,C#,四则运算,static,WriteLine,泛型,return,public From: https://www.cnblogs.com/HelloQLQ/p/17068140.html