get 和set访问器

longe521 2010-05-18 01:46:26
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访问器,请高手告知应该怎么改正啊
...全文
142 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangwenzhuang 2010-05-18
  • 打赏
  • 举报
回复
你的方法没有加(),呵呵,jf
JiuchunYoung 2010-05-18
  • 打赏
  • 举报
回复
不要 括号啊
jianshao810 2010-05-18
  • 打赏
  • 举报
回复
属性是不用加括号的
所以编译器被你弄迷糊了
itliyi 2010-05-18
  • 打赏
  • 举报
回复
楼主解决了 接点分
keeya0416 2010-05-18
  • 打赏
  • 举报
回复
属性是不用加括号的
所以编译器被你弄迷糊了
youyou2404 2010-05-18
  • 打赏
  • 举报
回复
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;
}
}
}
}
longe521 2010-05-18
  • 打赏
  • 举报
回复
哈哈,居然这个错误。。。。。多谢啦。
gxingmin 2010-05-18
  • 打赏
  • 举报
回复
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;
}
}
}



C#里的方法需要加括号
youyou2404 2010-05-18
  • 打赏
  • 举报
回复
InstanceMethod
youyou2404 2010-05-18
  • 打赏
  • 举报
回复
方法都不加括号怎么行啊
Forrest23 2010-05-18
  • 打赏
  • 举报
回复
啥意思?

110,530

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧