Есть ли лучший способ, чем следующая реализация переборки слов класса C#?Внедрение счетчика слов
ОБНОВЛЕНО КОД: Извините!
/// <summary>
/// A word counting class.
/// </summary>
public class WordCounter
{
Dictionary<string, int> dictTest = new Dictionary<string, int>();
/// <summary>
/// Enters a word and returns the current number of times that word was found.
/// </summary>
/// <param name="word">The word or string found.</param>
/// <returns>Count of times Found() was called with provided word.</returns>
public int Found (string word)
{
int count = 1;
return dictTest.TryGetValue (word, out count) ? ++dictTest[word] : dictTest[word] = 1;
}
}
Я что-то упустил или вы не используете слово в своем теле? –
@shakedown: '' tt '' должно быть 'word'. – SLaks
Да «tt» должно быть словом. спасибо, я исправил это. – kenny