LINQ execution problem RRS feed

  • Question

  • I am a bit confused with this LINQ execution

    I created a list and extracted some data into a 2nd list. Now i removed all items from 1st list.

    But if print the 2nd list now, i am still seeing the data in it.

    Can someone please help
    Tuesday, December 19, 2017 11:28 AM

All replies

  • Please reply to this quesion...
    Tuesday, December 19, 2017 1:11 PM
  • Your experiments show that the first list and second list represent different collections, therefore removing from one list does not affect the other one.

    But if you create the LINQ query, and do not yet execute it (for example, do not perform ‘.ToList()’), then change the first list, and then get the second list executing ‘.ToList()’ on the query, then the second list will reflect the changes made to first list.

    Tuesday, December 19, 2017 9:11 PM