请教一个简单的linq查询
这是前几天一位csdn的童鞋提出的问题,我用查询表达是语法做出来了。现在想请教下,用方法语法拉姆达表达式该怎么写。
List<int> numbers = new List<int>() { 1, 2, 3 };
List<string> words = new List<string>() { "one", "two", "three" };
List<string> romanNumberals = new List<string> { "I", "II", "III" };
var test = from n in numbers
let numIndex = numbers.IndexOf(n)
from w in words
let wordIndex = words.IndexOf(w)
from r in romanNumberals
let rIndex = romanNumberals.IndexOf(r)
where numIndex == wordIndex && wordIndex == rIndex
select new { Arabic = n, Word = w, Roman = r };
foreach (var item in test)
{
Console.WriteLine("{0},{1},{2}", item.Arabic, item.Word, item.Roman);
}
输出结果:
1,one,I
2,two,II
3,three,III
------解决方案--------------------
不过你可以参考我这两个回答:
http://topic.csdn.net/u/20120412/15/b36be23a-c01e-49b3-a011-3ca1b2acc68b.html
http://topic.csdn.net/u/20120718/10/50bf4829-f65d-404e-ba53-fbbd7932e7c1.html