using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace day11 { class Program {
//无返回值委托 public delegate void delegateShow(int n1, int n2); //有返回值委托 public delegate int GuangChaoshi(int a, int b); //泛型类用 public delegate void delegateAdd(); public event delegateAdd eventAdd; static void Main(string[] args) { //内置委托 #region 内置委托 Func<int, int, int> func2 = (n1, n2) => { return n1 / n2; }; Console.WriteLine("内置委托输出:" + func2(9, 3)); #endregion //匿名方法 #region 匿名方法 delegateShow sd; sd = (int n1, int n2) => { Console.WriteLine($"匿名方法输出:{n1 / n2}"); }; sd(12, 6); #endregion //lambda #region lambda GuangChaoshi gw = (n, b) => { return n / b; }; Console.WriteLine("lambda:" + gw(99, 3)); #endregion #region 泛型类 GetT<int> abc = new GetT<int>(); abc.A = 66; abc.B = 3; int jg = abc.GetSum(); Console.WriteLine("泛型类加泛型方法:"+jg); #endregion Console.ReadKey(); } //泛型类 public class GetT<T> where T : struct { public T A { get; set; } public T B { get; set; } //泛型方法 public T GetSum() { return (dynamic)A / (dynamic)B; } } } }
以上只是个人理解,如有错误欢迎指正