Why does the IEnumerable.Select() works in 1 of 2 cases ? Can not be inferred from usage

后端 未结 5 783
无人及你
无人及你 2021-01-18 03:26

I get this error message:

The type arguments for method \'System.Linq.Enumerable.Select(System.Collections.Generic.IE         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-18 03:43

    Select is not a replacement for a foreach. Use this instead:

    ObservableCollection documentsOC = new ObservableCollection();
    IEnumerable documents = _docRepo.GetDocumentsByPupilId(_selectedPupil.Id);
    foreach(var doc in documents)
    {
        documentsOC.Add(doc);
    }
    SelectedPupil.Documents.DocumentList = documentsOC;
    

提交回复
热议问题