在方法返回时出错 [英] Error when returning in method
问题描述
在我selectUser I类有:
In my selectUser class I have:
public checkEmail(string email)
{
peopleTableAdapters.PeoplesTableAdapter p = new peopleTableAdapters.PeoplesTableAdapter();
return p.checkEmail(email);
}
在客户端code我有:
In the client side code I have:
protected void Button1_Click(object sender, EventArgs e)
{
selectUser s = new selectUser();
try
{
s.checkEmail(email.Text);
}
catch(Exception e)
{
}
}
我收到此错误与回归p.checkEmail(电子邮件);错误的是:
I am getting this error with the "return p.checkEmail(email);" the error is:
错误307由于authentication.checkEmail(字符串)返回void,返回关键字一定不能跟一个对象前pression
"Error 307 Since 'authentication.checkEmail(string)' returns void, a return keyword must not be followed by an object expression"
有谁明白我做错了吗?
我不想返回任何数据,因为它不需要我只想所以它在try语句成功返回的东西。
I dont want to return any data because its not needed I just want to return something so it succeeds in the try statement.
推荐答案
这没有返回类型:
public checkEmail(string email)
我很惊讶这甚至的编译的,但也许编译器假定无效
时没有指定?我不知道它这样做。但无论哪种方式,没有返回类型。所以这是行不通的:
I'm surprised this even compiles, but maybe the compiler assumes void
when nothing is specified? I didn't know it did that. But either way, there's no return type. So this won't work:
return p.checkEmail(email);
如果该方法不具有返回类型,则它不能返回任何东西。你也别做返回的任何有价值的东西:
If the method doesn't have a return type, then it can't return anything. You also don't do anything with the returned value:
s.checkEmail(email.Text);
所以你并不需要在所有返回任何东西。
So you don't need to return anything at all.
此外,该错误也表明 p.checkEmail(电子邮件)
的本身的不返回任何东西。因此,试图返回的本身的东西是无效
返回类型只是使问题复杂化。
Furthermore, the error also suggests that p.checkEmail(email)
itself doesn't return anything. So trying to return something which itself is a void
return type is just compounding the problem.
由于没有在这个code返回任何值,你也许可以通过简单地不是要在所有返回任何解决此问题:
Since nothing in this code returns any value, you can probably resolve this by simply not trying to return anything at all:
public void checkEmail(string email)
{
peopleTableAdapters.PeoplesTableAdapter p = new peopleTableAdapters.PeoplesTableAdapter();
p.checkEmail(email);
}
这篇关于在方法返回时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!