Tag: 推断类型

为什么IEnumerable .Select()在2种情况中有1种工作? 无法从使用中推断出来

我收到此错误消息: The type arguments for method ‘System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)’ cannot be inferred from the usage. Try specifying the type arguments explicitly. 第一种方法使用IEnumerable.Select()没有问题? 第二种方法的问题在哪里? private void GetPupilsForSchoolclass() { ObservableCollection pupilsOC = new ObservableCollection ( _adminRepo.GetPupilsBySchoolclassId(_selectedSchoolclass.SchoolclassId).Select(p => new PupilViewModel(p, _adminRepo)) ); SelectedSchoolclass.PupilListViewModel = pupilsOC; } private void GetDocumentsForPupil() { ObservableCollection documentsOC = new ObservableCollection(); IEnumerable documents = _docRepo.GetDocumentsByPupilId(_selectedPupil.Id); […]