public void Add(UnityAction <T> action) { if (Instance == null) { return; } MethodAdd.Invoke(Instance, new object[] { action }); }
public static void Main(string[] args) { List <int> collection = new List <int>(); MethodMultiply method_1 = MyClass.MyFunction_1; Console.WriteLine(method_1(100)); Console.WriteLine("================================="); //MethodMultiply method_2 = (x) => x * 2000; int method_2(int i) { return(i * 2000); } Console.WriteLine(method_2(100)); Console.WriteLine("================================="); Console.WriteLine(MyClass.MyFunction_2(100, method_2)); Console.WriteLine("================================="); Console.WriteLine(MyClass.MyFunction_2(100, x => x * 2)); Console.WriteLine("================================="); Func <int, int> func = (x) => x * 2; Console.WriteLine(MyClass.MyFunction_3(100, func)); Console.WriteLine("================================="); Console.WriteLine(MyClass.MyFunction_3(100, x => x * 2)); Console.WriteLine("================================="); MethodAdd method_3 = collection.Add; MethodAdd method_4 = delegate(int i) { collection.Remove(i); }; MethodAdd method_5 = i => collection.Remove(i); method_4 += Console.WriteLine; Action <int> action = x => collection.Add(x); Action <int> action_1 = collection.Add; Action <int> action_2 = delegate(int x) { collection.Add(x); }; Action action_3 = delegate() { Console.WriteLine("gsdajhdbajk"); }; method_3(500); method_3(600); method_3(700); method_3(800); method_3(900); method_3(1000); method_4(600); method_4(800); method_4(1000); Console.WriteLine("================================="); action(100); action(200); action(300); action(400); Predicate <int> func_1 = delegate(int i) { return(collection.Contains(i)); }; Predicate <int> func_2 = i => collection.Contains(i); Console.WriteLine(func_1(500)); Console.WriteLine("================================="); foreach (int a in collection) { Console.WriteLine(a); } Console.WriteLine("================================="); var newCollection_1 = collection.Where(x => x > 700); foreach (var z in newCollection_1) { Console.WriteLine(z); } Console.WriteLine("================================="); var newCollection_2 = collection.Take(4); foreach (var z in newCollection_2) { Console.WriteLine(z); } Console.WriteLine("================================="); var newCollection_3 = collection.FirstOrDefault(); Console.WriteLine(newCollection_3); Console.WriteLine("================================="); var myClassList = new List <MyClass>(); { new MyClass { MyProperty_2 = 100 }; new MyClass { MyProperty_2 = 200 }; new MyClass { MyProperty_2 = 300 }; } myClassList.Add(new MyClass { MyProperty_2 = 400 }); myClassList.Add(new MyClass { MyProperty_2 = 500 }); myClassList.Add(new MyClass { MyProperty_2 = 600 }); var newCollection_4 = myClassList.Where(x => x.MyProperty_2 > 100).Select(x => x.MyProperty_2).ToList(); myClassList.Add(new MyClass { MyProperty_2 = 1000 }); foreach (var z in newCollection_4) { Console.WriteLine(z); } Console.WriteLine("================================="); var newCollection_5 = myClassList.Reverse <MyClass>(); foreach (var z in newCollection_5) { Console.WriteLine(z.MyProperty_2); } Console.WriteLine("================================="); var newCollection_6 = myClassList.SkipWhile(x => x.MyProperty_2 <= 300).Select(x => x.MyProperty_2); foreach (var z in newCollection_6) { Console.WriteLine(z); } Console.WriteLine("================================="); List <MyClass> /*IEnumerable<MyClass>*/ MyFunc(List <MyClass> mc, Predicate <int> pr) { //var vt = mc.Where(x => x.MyProperty_2 < 600); //var vt = mc.Where(x => pr(x.MyProperty_2)); var vt = new List <MyClass>(); foreach (var vm in mc) { if (pr(vm.MyProperty_2)) { vt.Add(vm); } } return(vt); } var cvb = MyFunc(myClassList, x => x < 600); foreach (var df in cvb) { Console.WriteLine(df.MyProperty_2); } }