我有一个由2个元素组成的列表,一个字符串和一个浮点数,我试图按照float元素的降序对其进行排序,然后打印列表的前5个元素,但我不想在保存时执行此操作排序列表在另一个列表中。我在最后一行代码上遇到了一些麻烦。这是我的代码,有帮助吗?
var list = new List<Tuple<string, float>>();
for(i=100;i==0;i--){
list.Add(new Tuple<string, float>("randomtext", i);
}
(from s in list orderby s.Item2 descending select s).Take(5);
You are using
Tuple<T1, T2>
and it has properties likeItem1
andItem2
and thus you can do likeWell, per your post if you don't want this list to be stored and want to print the selected result then you can use
Foreach()
method