What does "ToList" do?

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

If I have the following code:

List<DataRow> trsTrades = selected.ToList();

What does ToList do? Does it copy all of the items in trsTrades, or
does it create a list containing just pointers (to their corresponding
items in the original list, trsTrades)?

Thanks,
 
Hi,

If I have the following code:

List<DataRow> trsTrades = selected.ToList();

What does ToList do? Does it copy all of the items in trsTrades, or
does it create a list containing just pointers (to their corresponding
items in the original list, trsTrades)?

Strictly speaking, neither. If DataRow is a struct, it will be copied.
If it is a class or interface, it will create a List and add the
references to the datarows to it. No pointers involved here (and
that's good, you should think twice before using unsafe code in any
place but interfacing native libraries).
 
Hi,





Strictly speaking, neither. If DataRow is a struct, it will be copied.
If it is a class or interface, it will create a List and add the
references to the datarows to it. No pointers involved here (and
that's good, you should think twice before using unsafe code in any
place but interfacing native libraries).

Thanks! This is helpful
 
Back
Top