110,530
社区成员
发帖
与我相关
我的任务
分享
namespace ActingConsoleApp
{
delegate int Mydelegate();
class Program
{
static void Main(string[] args)
{
test p = new test();
Mydelegate m = new Mydelegate(p.InstanceMethod);
m();
m = new Mydelegate(test.StaticMethod);
m();
}
public class test
{
public int InstanceMethod()
{
Console.WriteLine("正在使用非静态方法InstanceMethod()....");
return 0;
}
public static int StaticMethod()
{
Console.WriteLine("正在使用静态方法StaticMethod...");
return 0;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ActingConsoleApp
{
delegate int Mydelegate();
class Program
{
static void Main(string[] args)
{
test p = new test();
Mydelegate m = new Mydelegate(p.InstanceMethod);
m();
m = new Mydelegate(test.StaticMethod);
m();
}
}
public class test
{
public int InstanceMethod() //少了括号
{
Console.WriteLine("正在使用非静态方法InstanceMethod()....");
return 0;
}
static public int StaticMethod() //少了括号
{
Console.WriteLine("正在使用静态方法StaticMethod...");
return 0;
}
}
}