Skip to content

Select then ToList() doesn't work ? #386

Description

@LoisBoombyte

Hi, I executed this simple test in Unity and the ToList() doesn't work well... ?!

public List<InboxItem> _firstList = null;

 public class InboxItem
 {
     public int int1;
     public float float1;
     public int int2;
 }

 //I just initialize the list with 10.000 items
 private void Start()
 {
     _firstList = new List<InboxItem>(100000);
     for (int i = 0; i < 100000; i++)
     {
         _firstList.Add(new InboxItem()
         {
             int1 = i,
             float1 = i,
             int2 = 2 * i
         });
     }
 }

private void TestSelectThenToListHyperLinq()
 {
     Debug.Log("TestSelectThenToListHyperLinq");
     var select = _firstList.AsValueEnumerable().Select(x => x.int1);
     var list = select.ToList();
     var array = select.ToArray();
     Debug.Log("list count = " + list.Count);  //return 0 !!!!
     Debug.Log("array Length = " + array.Length); //return n
 }

 private void TestSelectThenToListLinq()
 {
     Debug.Log("TestSelectThenToListLinq");
     var select = _firstList.Select(x => x.int1);
     var list = select.ToList();
     var array = select.ToArray();
     Debug.Log("list count = " + list.Count); //return n
     Debug.Log("array Length = " + array.Length); //return n
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions