
asp.net c#中定义函数的问题!
publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,Eve...
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
static void sayhello(string name)
{
response.write("hello" + name);
}
public static void Main()
{
sayhello("pings");
}
}
我把 static void sayhello(string name)
{
response.write("hello" + name);
}
public static void Main()
{
sayhello("pings");
}
写在 public partial class _Default : System.Web.UI.Page
{}
这里面怎麼不对啊
说response 不存在目前内容中
应该要写到哪里的啊?
谢谢了。
leon382 可是我打的时候,它都不自动出来
一般都会自动弹出的啊!
fancyaj 你这样写 是有效果了
不过我要做个我开始写的 要定义静态函数
该怎麼写了?我试著把它写在public partial class _Default : System.Web.UI.Page
{}的外面也不可以。你知道怎麼弄吗? 展开
{
protected void Page_Load(object sender, EventArgs e)
{
}
static void sayhello(string name)
{
response.write("hello" + name);
}
public static void Main()
{
sayhello("pings");
}
}
我把 static void sayhello(string name)
{
response.write("hello" + name);
}
public static void Main()
{
sayhello("pings");
}
写在 public partial class _Default : System.Web.UI.Page
{}
这里面怎麼不对啊
说response 不存在目前内容中
应该要写到哪里的啊?
谢谢了。
leon382 可是我打的时候,它都不自动出来
一般都会自动弹出的啊!
fancyaj 你这样写 是有效果了
不过我要做个我开始写的 要定义静态函数
该怎麼写了?我试著把它写在public partial class _Default : System.Web.UI.Page
{}的外面也不可以。你知道怎麼弄吗? 展开
3个回答
展开全部
首先,ASP.NET的程序运行在IIS中,因此根本不需要Main方法。其次,你的 sayhello 方法应该在 Page_Load 方法中被调用。最后,由于你的 sayhello 方法是 static 的,因此自然找不到作为 _Default 类属性的 Response。此外,你还需要注意Response属性及其Write方法的大小写。
需要改写成:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
sayhello("pings");
}
private void sayhello(string name)
{
Response.Write("hello" + name);
}
}
需要改写成:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
sayhello("pings");
}
private void sayhello(string name)
{
Response.Write("hello" + name);
}
}
展开全部
Response.Write
不是 response.write
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
void sayhello(string name)
{
Response.Write("hello" + name);
}
public void Main()
{
sayhello("pings");
}
}
不是 response.write
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
void sayhello(string name)
{
Response.Write("hello" + name);
}
public void Main()
{
sayhello("pings");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void sayhello(string name)
{
//Response.write("hello" + name);
Response.Write("hello" + name);
}
public void Main()
{
sayhello("pings");
}
}
这样就OK了,还有static不可以随便的应用
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void sayhello(string name)
{
//Response.write("hello" + name);
Response.Write("hello" + name);
}
public void Main()
{
sayhello("pings");
}
}
这样就OK了,还有static不可以随便的应用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询