我正在写一个简单的语言翻译器,它会呈现英文单词并询问相应的外来词。到目前为止,代码将从数组中选择一个随机词,但是我现在正试图让它从列表中选择相应的外来词。这是到目前为止的代码:
public class Words
{
public int spanishindex;
string[] EnglishWords = { "Yellow", "Yello", "Yelow", "Yllow", "ellow" };
string[] SpanishWords= { "giallo", "giall", "iallo", "gllo", "lo" };
public String GetRandomWord()
{
Random randomizer = new Random();
index = randomizer.Next(EnglishWords.Length);
string randomword = EnglishWords[randomizer.Next(index)];
spanishindex= index;
return randomword;
}
public String MatchSpanishWord()
{
string matchword = SpanishWords[spanishindex];
return matchword;
}
}
我的想法是通过在 MatchSpanishWord 方法中传入与随机值相反的索引值,我会得到相应的单词(因为列表是按顺序排列的)
因此,如果选择了“ellow”,则对应的西班牙语应该是“lo”
任何帮助将不胜感激,谢谢。