简体   繁体   中英

How to convert a list<T> to an array T[] using c#

I have a list with some 10 records. Each record have two values.

item->[0] = name:"apple" ,price:10
item->[1] = name:"mango",price :20

and so on.

I want to convert this to an array like this.

 var items= [
      {name: "apple", price: 10},
      {name: "mango", price: 20},
      /* ... */
    ];

Thanks in Advance

您应该只能够通过LINQ的ToArray()方法来处理此问题:

var array = yourCollectionOfRecords.ToArray();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM