class AddItemOption
{
//Fields that contain class data
string input = Console.ReadLine();
//Methods that define class functionality
public string myFunction(string Value)
{
switch (input)
{
case "Umbrella":
Console.WriteLine("Umbrella is selected");
break;
case "Rain Coat":
Console.WriteLine("Raincoat is selected");
break;
case "Boots":
Console.WriteLine("Boots is selected");
break;
case "Hood":
Console.WriteLine("Hood is selected");
break;
default:
Console.WriteLine("Input not reconized, please choose another item");
break;
}
}
「すべてのコードパスが値を返すわけではありません」というエラーが表示されます。myFunction(string Value)からです。これを返す方法や、パラメータを機能させるために何を入力するかがわかりません。その下にも何か必要ですか?私はクラスに不慣れです。これをすべて間違っているのか、それともswitchステートメントを使用する必要があるのかを教えてください。
public AddItemOption(string input)
{
}
Shyjuから私はそれを次のように変更しました:
class AddItemOptionOne
{
//Fields that contain class data
string input = Console.ReadLine();
//Methods that define class functionality
public string myFunction(string Value)
{
switch (input)
{
case "Key Chain":
return "Key Chain is selected";
break;
case "Leather Armor":
return "Leather Armor is selected";
break;
case "Boots":
return "Boots is selected";
break;
case "Sword":
return "Sword is selected";
break;
default:
return "Input not reconized, please choose another item";
break;
}
}
ただし、ブレークは認識されません。「到達不能コードが検出されました」