wordlist()
方法,返回从结构中的字段复制的字符串数组。
但问题是此方法返回System.String[ ]
,而不是返回数组中的所有对象。我试图做foreach
,但我认为不是问题。不幸的是,我无法弄明白。
public struct wordStruct
{
public string Sword;
}
class StringCounterClass : IOrederedWordStructure
{
wordStruct[] array = new wordStruct[10];
int totalInsertedWords = 0;
public string[] wordList()
{
string [] wordArray = new string[array.Length];
for (int i = 0; i < wordArray.Length; i++)
{
wordArray[i] = array[i].Sword;
}
return wordArray;
}
public void insertWord(string[] words)
{
int insertwordLength = words.Length;
totalInsertedWords = insertwordLength;
string[] myWord = words;
foreach (string word in myWord)
{
for (int i = 0; i < insertwordLength; i++)
{
array[i].Sword = myWord[i];
}
}
}
答案 0 :(得分:0)
检查您的拼写错误
} return wordArray;