【发布时间】:2014-09-03 23:43:46
【问题描述】:
为什么MainWindow/this.ab 被隐藏了,看不到了?我想应该在mainWindows 中看到私人信息。
如果我把return 没有放在方法的末尾,C# 似乎会抛出错误Not all code return path value。
c#可以同时返回string和void吗?如果我错了,更好的代码是什么?在 PHP 中,代码很容易工作。我需要知道它如何在 C# 中工作。
public static string a(string type,string a)
{
return MainWindow.ab(type, a);
}
public static void a(string type)
{
MainWindow.ab(type);
}
private string ab(string type,string a=null)
{
if (type == "1")
{
return "1";
}
}
【问题讨论】:
-
这里有很多问题。首先,实例方法(非
static)必须通过引用该类的实例来调用。其次,您的非void方法必须在所有代码路径上返回一个值。如果type != "1",ab的返回值是多少?我建议你先阅读Methods (C# Programming Guide)