C#中使用委托的3种方式代码示例
程序员文章站
2023-11-29 17:37:46
using system;
namespace delegatedemo
{
class program
{
private dele...
using system; namespace delegatedemo { class program { private delegate int cacu(string str); static void main(string[] args) { //1 cacu cacu = new cacu(cacuinstance); console.writeline(cacu("hello,wrold")); //2 cacu cacu1 = new cacu(delegate(string str) { return str.length; }); console.writeline(cacu1("hello,wrold")); //3 cacu cacu2 = new cacu((str) => { return str.length; }); console.writeline(cacu2("hello,wrold")); } static int cacuinstance(string str) { return str.length; } } }