adsense

Saturday, September 4, 2021

Converting ICollection to List

 

We can use the System.Linq namespace to convert ICollection<T> to List<T>    as dsiplays below.

//class definitions

public class Students
{
    public ICollection<Courses> Courses{get;set;}
}

public class Courses
{
    public ICollection<Students> Students{get;set;}
}

//end class definition

//create the List

using System.Linq; 


List<Students> listOfStudents= lstStudents.OfType<Students>().ToList();



cheers,

Samitha