菜鸟提问,关于return返回值的问题,报一个not all code paths return a value错误? public int compare(int x0,int x1,int x2,int x){ if(x0>x) return 0; if(x1>x) return 1; if(x2>x) return 1; }怎么会报这个错,我对C#语法不是太懂,我以前用VB的,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果X同时大于x0,x1,x2那么返回什么? 我也遇到过,在EXE中出错,但在DLL中不出错. 用 if elseif else必须有个ELSE即上面条件都不符合时,返回一个值 public int compare(int x0,int x1,int x2,int x){ if(x0>x) return 0; if(x1>x) return 1; if(x2>x) return 1; return 999;以上都不满足时返回 } public int compare(int x0,int x1,int x2,int x){ if(x0>x) return 0; if(x1>x) return 1; if(x2>x) return 2; return 999;以上都不满足时返回 } public int compare(int x0,int x1,int x2,int x){return (x0>x)?0:((x1>x)?1:((x2>x)?2:-1));}或public int compare(int x0,int x1,int x2,int x){ if(x0>x) return 0; else if(x1>x) return 1; else if(x2>x) return 2; else return -1;} 谢谢可我这样:也出错public int compare(int x0,int x1,int x2,int x){ if(x0>x) return 0; } 关于C#事件 关于数据库的一点问题 如何让自定义event在 属性浏览器中显示出来? 一个c#聊天程序,为什么接收时只接收了第一个字母? 高手请进~~~~~~~~ 我打不开c/c++区,所以在这提个关于输出格式的问题,大家别见怪! 求一数据库解决方案[有经验者请进] c#窗口实时更新 窗体渲染问题 DotNet高手300分有请,System.Net.WebRequest/System.Net.HttpWebRequest以post方式访问servlet c#能开发手机游戏吗 在DataGrid中定义了一个超级链接列,该如何获取用户点击的行的行号?
必须有个ELSE
即上面条件都不符合时,返回一个值
{
if(x0>x) return 0;
if(x1>x) return 1;
if(x2>x) return 1;
return 999;以上都不满足时返回
}
{
if(x0>x) return 0;
if(x1>x) return 1;
if(x2>x) return 2;
return 999;以上都不满足时返回
}
{
return (x0>x)?0:((x1>x)?1:((x2>x)?2:-1));
}
或public int compare(int x0,int x1,int x2,int x)
{
if(x0>x) return 0;
else if(x1>x) return 1;
else if(x2>x) return 2;
else return -1;
}
可我这样:也出错
public int compare(int x0,int x1,int x2,int x)
{
if(x0>x) return 0;
}