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;
}
}
}
编译出现错误说是应为get和set访问器,请高手告知应该怎么改正啊
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;
}
}
}
编译出现错误说是应为get和set访问器,请高手告知应该怎么改正啊
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;
}
}
}C#里的方法需要加括号
{
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;
}
}
}
}