这是我正在尝试的一个小型Scrabble项目,并希望得到一些意见,了解我可能做错了什么。我有一个字母和它们对应分数的“词典”,还有一个单词列表。我的想法是找到每个单词中出现的字母,然后将它们的分数相加。
// 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
};
非常感谢您的帮助。
谢谢。