标题:[求助]为什么这里要有return
取消只看楼主
hanxuema
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2006-7-28
 问题点数:0 回复次数:0 
[求助]为什么这里要有return

using System;

class Class1
{
public static void Main()
{
string command;

while ((command = Console.ReadLine()) != "exit")
{
switch (command)
{
case "get":
doget();
break;

case "put":
doput();
break;

case "default":
doDefault();
break;
}
}
}

public static int doget()
{
Console.WriteLine("get is ok");
return 0;
}

public static int doput()
{
Console.WriteLine("put is ok");
return 0;
}
private static int doDefault()
{
Console.WriteLine("the command is wrong");
Console.WriteLine("whileApp V0.1 supprts:");
Console.WriteLine("\tget:\t");
Console.WriteLine("\tput:\t");
Console.WriteLine("\texit:\t");

return 0;
}
}



关于这个程序,请问在 public static int doget()
{
Console.WriteLine("get is ok");
return 0;
}中为什么一定要return 0; 我不写return好像不行,请问是为什么,错误报告说需要一个int,谁能详细解释一下,因为为什么要public static int doget 里面的这个int 我都不知道

或者return 100可以吗?

谢谢大家

搜索更多相关主题的帖子: return 
2006-08-11 03:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-83323-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.022300 second(s), 10 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved