一个小小问题!!

zhang119 2003-08-26 06:03:53
using System;
class Myclass
{
public int x =0;
public Myclass(int x)
{
this.x = x;
}
public void Main()
{
Myclass Mc = new Myclass(1);
Console.WriteLine("x value is {0}",x);
}
}
报错:Prpgram'路径/文件'does not have an entry point defined
不知道是为什么??高手做答!!
...全文
13 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
kuangren 2003-08-26
  • 打赏
  • 举报
回复
Main方法应该是static的
也就是
改成static void Main()就好了
bat800 2003-08-26
  • 打赏
  • 举报
回复
不明白!
cppTrier 2003-08-26
  • 打赏
  • 举报
回复
sigh...来晚了,问题就是出在Main()必须是static的,因为只能通过类来调用类的静态方法。如果Main()是某个类的成员函数,那么就会出现 没有这个类的对象就不能调用Main(),但没有Main()就不能进入程序创建类的对象。

从C++转到C#的程序员一开始可能会奇怪,为什么Main()包涵在一个类里面还能成为程序的入口呢,其实这是因为Main()被申明为static不需要类的对象实例就能调用。
moreqiter 2003-08-26
  • 打赏
  • 举报
回复
Main方法必须为static
大户翁 2003-08-26
  • 打赏
  • 举报
回复
using System;
class Myclass
{
public int x =0;
public Myclass(int x)
{
this.x = x;
}
static void Main()
{
Myclass Mc = new Myclass(1);
Console.WriteLine("x value is {0}",Mc.x);
}
}
MarcuseXiao 2003-08-26
  • 打赏
  • 举报
回复
没有入口嘛
brightheroes 2003-08-26
  • 打赏
  • 举报
回复
如下:
[STAThread]
static void Main()
{
Application.Run(new FormClientMain());
//Application.Run(new TestQuery());

}

110,571

社区成员

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

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

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