このケースの周りに頭を浮かべるように要請してください。一致する単語が複数ある場合はどうなりますか?例えば、単語リストと一致する別の単語が与えられたとする。 getvalue( "paddy")を渡すと100になります。Listからマッチした単語が同じ場合は、100を返します。 ありがとうございます。リストから一致する単語を返します<string>
Console.WriteLine(getvalue("sam"));
public static int getvalue (string c)
{
//here would be creating a list
List<string> wordlist = new List<string> { "sam", "paddy", "murphy",
"saint"};
string s;
if(wordlist.Any(c.Contains))
{
s = c;
Console.WriteLine("found word" + s);
}
//this should be matching the object found word
return c == "sam" ? 100 : -10;
}
return c == "sam"? 100: "水田"? 100:-10; –
この質問は非常に不明です。サンプルの入力/出力を提供することがあります。 –
@YahyaHusseinあなたはそれを処理するためのよりよい方法が必要な場所を十分に閉じることができます。長いListの場合は、すべてを代入する作業があります。 – khmub