简体   繁体   English

如何检索HashSet的第二项 <Tuple<string, int> &gt;

[英]How to retrieve second item of HashSet<Tuple<string, int>>

I've a HashSet<Tuple<string, int>> In the second item I've numbers (1,18,5,46). 我有一个HashSet<Tuple<string, int>>在第二项中,我有数字(1,18,5,46)。

I'd like to get biggest number of in these items. 我想从这些物品中获取最多的数量。

I'm new in programming so please forgive me for question. 我是编程方面的新手,请原谅我的问题。

I've just found a way and want to share: int max = students.Max(kvp => kvp.Item2); 我刚刚找到了一种方法,想分享一下: int max = students.Max(kvp => kvp.Item2);

You can do this 你可以这样做

using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main()
    {
        var students = new List<Tuple<string, int>>();

        students.Add(new Tuple<string, int>("test", 10));
        students.Add(new Tuple<string, int>("test", 10));

        Console.Write(students.Max(t => t.Item2));
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 HashSet 中检索实际项目<T> ? - How to retrieve actual item from HashSet<T>? 为HashSet编写IEqualityComparator <Tuple<T, int> &gt; - Writing IEqualityComparator for HashSet<Tuple<T, int>> 如何在词典中查找键 <int,List<Tuple<string,string> &gt;&gt;,以使列表包含具有给定Item1和Items的元素 - How to find keys in a Dict<int,List<Tuple<string,string>>> such that the list contains elements with given Item1 and Items 如何转换清单 <Tuple<string, int> &gt;转换为字符串[]? - How to convert List<Tuple<string, int>> to string[]? 如何对ConcurrentBag进行排序 <Tuple<string,int,decimal> &gt;()由C#中的Item3提供? - How to sort ConcurrentBag<Tuple<string,int,decimal>>() by Item3 in c#? 如何制作HashSet <HashSet<int> &gt;工作正常吗? - How to make a HashSet<HashSet<int>> work appropriately? 如何从List <Tuple <int,int,string >>获取字符串数组? - How to get array of string from List<Tuple<int, int, string>>? 从元组列表中删除元素<int, int>如果任何组件在另一个 HashSet 列表中<int>在 C# 中 - Remove element from list of Tuple<int, int> if any component is in another list of HashSet<int> in C# 是否可以将列表框数据源设置为列表 <Tuple<string, string, int> &gt;仅限于项目1? - Is it possible to set listbox datasource to List<Tuple<string, string, int>> Item1 only? 如何从元组列表中提取 item2(Value) 列表<tuple<int,int> &gt;? </tuple<int,int> - How to extract List of item2(Value) from a List of Tuples Like List<Tuple<int,int>>?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM