C# 为ConcurrentDictionary.Select()声明变量

C# 为ConcurrentDictionary.Select()声明变量,c#,linq,dictionary,C#,Linq,Dictionary,我有一个简单的ConcurrentDictionary,我试图选择值的子集 我正在使用这段代码,唯一能让它工作的方法是使用var来声明testStudents。此代码的正确声明是什么?我试过List和IEnumratable,但都不起作用 public ConcurrentDictionary<string, Student> _Student = new ConcurrentDictionary<string, Student>();

我有一个简单的ConcurrentDictionary,我试图选择值的子集

我正在使用这段代码,唯一能让它工作的方法是使用var来声明testStudents。此代码的正确声明是什么?我试过List和IEnumratable,但都不起作用

            public ConcurrentDictionary<string, Student> _Student = new ConcurrentDictionary<string, Student>();

            var testStudents = this._Student.Values.Select( s => s.Name = "jack");

谢谢大家。看来我用错方法了。Where方法是我需要使用的

IEnumerable<Student> testStudents
     = this._Student.Values.Where( s => s.Name = "jack");

看起来像是一张单子?哦,通过打电话来实现它。列出它并检查测试学生以确定。事实上,您是否将每个学生的姓名设置为jack?我假设您打算使用where=>s.name==jack。在这种情况下,testStudents将是一个IEnumerable。您当前的表达式将每个值的名称设置为jack,并计算为string.IEnumerable…但您可以不使用var,因为编译器将推断正确的类型。Select表示映射集合必须通过映射函数将每个元素转换为另一个元素。其中表示按条件筛选集合。可能您需要类似var testStudents=this的内容。_Student.Values.Where s=>s.Name=jack;