【发布时间】:2011-09-22 20:20:26
【问题描述】:
这是我正在修补的一个小拼字游戏项目,想就我可能做错的地方获得一些意见。我有一个字母的“字典”及其各自的分数和一个单词列表。我的想法是找出每个单词中的字母并将分数相加。
// Create a letter score lookup
var letterScores = new List<LetterScore>
{
new LetterScore {Letter = "A", Score = 1},
// ...
new LetterScore {Letter = "Z", Score = 10}
};
// Open word file, separate comma-delimited string of words into a string list
var words = File.OpenText("c:\\dictionary.txt").ReadToEnd().Split(',').ToList();
// I was hoping to write an expression what would find all letters in the word (double-letters too)
// and sum the score for each letter to get the word score. This is where it falls apart.
var results = from w in words
join l in letterScores on // expects an 'equals'
// join l in letterScores on l.Any(w => w.Contains(
select new
{
w,
l.Score
};
任何帮助将不胜感激。 谢谢。
【问题讨论】: