첫 번째 프로그램을 작성하려고합니다. 채팅 시뮬레이터로 사용하려고합니다. 그러나 오류가 발생합니다. 오류 1 'Chat_Simulator.Program.UserConnection() : 모든 코드 경로 값 여기서'switch 문을 사용하여 모든 코드 경로가 값을 반환하지 않습니다'
를 반환하는 코드이다
string NUsername = UserConnection();
Console.WriteLine("You have connected to:" + NUsername);
static String UserConnection()
{
Console.WriteLine("Connecting to random user...");
Thread.Sleep(2000);
Console.Clear();
Random random = new Random();
//picks random user
switch (random.Next(4))
{
case 0:
{
Console.WriteLine("Connecting you to Jerry");
string Cusername = "Jerry";
return Cusername;
//not sure if this works?
}
case 1:
{
Console.WriteLine("Connecting you to Stinger8");
string Cusername = "Stinger8";
return Cusername;
}
case 2:
{
Console.WriteLine("Connecting you to MadamThus");
string Cusername = "Madamthus";
return Cusername;
}
case 3:
{
Console.WriteLine("Connecting you to Kawai49");
string Cusername = "Kawai49";
return Cusername;
}
}
'UserConnection' 어떤 점에서'string'를 반환해야합니다, 그것은 일치하는 경우에만 하나를 반환합니다 상황에서 : 실제로 뭔가 잘못된 것이 분명합니다 이후, 기본 값을 반환 통해
Exception
를 선호 적어도 하나의 사례 진술. 스위치에 'default'대/소문자를 추가해야합니다 - [예제 참조] (http://msdn.microsoft.com/en-us/library/06tc147t.aspx). – James기본 대소 문자를 추가하십시오 : http://msdn.microsoft.com/en-us/library/06tc147t.aspx –