婴儿奶粉什么最好,掩耳盗铃读后感,宝象国共有几座大象
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace consoleapp1 { class program { static void main(string[] args) { action action = new action(method); console.writeline(action.gettype().isclass); } static void method() { } } }
example1:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace consoleapp1 { class program { static void main(string[] args) { action action = new action(method); action.invoke(); action(); } static void method() { console.writeline("hello delegate"); } } }
example2:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace consoleapp2 { class program { static void main(string[] args) { action<string, int> action = new action<string, int>(method); action.invoke("张三",18); action("李四",19); } static void method(string name, int age) { console.writeline($"我叫{name}今年{age}岁"); } } }
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace consoleapp2 { class program { static void main(string[] args) { func<double, double, double> func = new func<double, double, double>(add); double result1 = func.invoke(1.5,3.5); console.writeline(result1); double result2 = func(2.5,4.5); console.writeline(result2); } static double add(double x, double y) { double result = x + y; return result; } } }
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace consoleapp2 { class program { static void main(string[] args) { func<string> func = new func<string>(findname); sayhello(func); } static void sayhello(func<string> finddelegate) { console.writeline($"hello {finddelegate()}"); } static string findname() { return "小明"; } } }
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace consoleapp3 { public delegate product productdelegate(); public delegate void logdelegate(product product); class program { static void main(string[] args) { wrapproduct product = new wrapproduct(); logger logger = new logger(); wrapfactory wrapfactory = new wrapfactory(); productdelegate productdelegate1 = new productdelegate(product.gettoy); productdelegate productdelegate2 = new productdelegate(product.getstationery); logdelegate logdelegate = new logdelegate(logger.log); box box1 = wrapfactory.getbox(productdelegate1,logdelegate); box box2 = wrapfactory.getbox(productdelegate2,logdelegate); console.writeline($"product1 {box1.product.name} the price is {box1.product.price}"); console.writeline($"product2 {box2.product.name} the price is {box2.product.price}"); } } public class product { public string name { get; set; } public int price { get; set; } } public class box { public product product { get; set; } } public class wrapfactory { public box getbox(productdelegate productdelegate,logdelegate logdelegate) { box box = new box(); product product = productdelegate.invoke(); if (product.price>50) { logdelegate.invoke(product); } box.product = product; return box; } } public class wrapproduct { public product gettoy() { product product = new product(); product.name = "toy"; product.price = 100; return product; } public product getstationery() { product product = new product(); product.name = "stationery"; product.price = 30; return product; } } public class logger { public void log(product product) { console.writeline($"product {product.name} created at {datetime.now.tostring()}"); } } }
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace consoleapp4 { class program { static void main(string[] args) { func<int, int, int> func1 = new func<int, int, int>((int a, int b) => { return a + b; }); var func2 = new func<int,int,int>((a, b) => { return a * b; }); calculate(func1,2,3); calculate(func2,3,4); calculate((x,y)=> { return x - y; },7,1); } static void calculate<t>(func<t,t,t> func,t x,t y) { t z = func.invoke(x,y); console.writeline(z); } } }
namespace consoleapp5 { class father { } class son : father { } class program { static void main(string[] args) { func<father> func = new func<father>(method); } static son method() { son son = new son(); return son; } } }
namespace consoleapp5 { class father { } class son : father { } class program { static void main(string[] args) { action<son> action = new action<son>(method); } static void method(father father) { } } }
namespace consoleapp6 { class program { static void main(string[] args) { var func = new func<int, int, int>(m1); func += m2; func += m3; func(3,3); console.writeline(func(3,3)); } static int m1(int x, int y) { console.writeline(x+y); return x + y; } static int m2(int x, int y) { console.writeline(x - y); return x - y; } static int m3(int x, int y) { console.writeline(x*y); return x * y; } } }
namespace consoleapp7 { class program { static void main(string[] args) { var action = new action(m1); action += m2; action += m3; action.invoke(); action -= m2; action.invoke(); } static void m1() { console.writeline("m1 is invoked"); } static void m2() { console.writeline("m2 is invoked"); } static void m3() { console.writeline("m3 is invoked"); } } }
namespace consoleapp8 { class program { static void main(string[] args) { var action1 = new action(m1); var action2 = new action(m2); var action3 = new action(m3); action action = null; action = (action)delegate.combine(action,action1); action = (action)delegate.combine(action,action2); action = (action)delegate.combine(action,action3); action(); console.writeline(); action = (action)delegate.remove(action,action2); action(); } static void m1() { console.writeline("m1 is invoked"); } static void m2() { console.writeline("m2 is invoked"); } static void m3() { console.writeline("m3 is invoked"); } } }
namespace consoleapp9 { class program { static void main(string[] args) { thread thread1 = new thread(new threadstart(m1)); thread thread2 = new thread(new threadstart(m2)); thread1.start(); thread2.start(); } static void m1() {} static void m2() {} } }
namespace consoleapp10 { class program { static void main(string[] args) { task task = new task(new action(m1)); task.start(); } static void m1() { } } }
namespace consoleapp11 { class program { static void main(string[] args) { calculator calculator = new calculator(); func<int, int, int> func = new func<int, int, int>(calculator.add); iasyncresult asyncresult = func.begininvoke(2,3,null,null); console.writeline($"结果是{func.endinvoke(asyncresult)}"); console.writeline("计算完成"); } } public class calculator { public int add(int a, int b) { return a + b; } } }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论