简体   繁体   English

如何转换清单 <T> 使用C#到数组T []

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

I have a list with some 10 records. 我有一个包含10条记录的列表。 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# 将数组转换为泛型 T List<> - C# Convert array to generic T List<> 转换列表<t>到 C# 中的数组</t> - Convert List<T> to Array in C# 我怎样才能转换IEnumerable <T> 列表 <T> 在C#? - How can I convert IEnumerable<T> to List<T> in C#? 将任何类型的数组转换为List <T> (C#) - Convert array of any type to List<T> (C#) 如何转换List <DataRow> 列表 <T> 在C#? - How to convert List<DataRow> to List<T> in C#? 如何从列表转换<object>列出<t>在 c# 中?<div id="text_translate"><p> 我有一个 Class:</p><pre> public class Element { public List&lt;object&gt; objects { get; set; } }</pre><p> 还有一个 Class:</p><pre> public class Node { public long id { get; set; } }</pre><p> 我传入一个List&lt;object&gt; nodes 。 那么有什么方法可以将这些List&lt;object&gt; objects转换为List&lt;Node&gt; nodes ?</p><p> 我试过这种方式,但它不起作用List&lt;Node&gt; nodes = objects.Select(s =&gt; (nodes)s).ToList();</p></div></t></object> - How to convert from List<object> to List<T> in c#? C# - 如何转换懒惰 <List<T> &gt;懒惰 <List<U> &gt;? - C# - How to convert Lazy<List<T>> to Lazy<List<U>>? 数组列出 <t> C# - Array to List<t> c# 将Json转换为List <T> 使用Json.NET在C#中 - Convert Json into List<T> in C# using Json.NET 将匿名类型转换为列表 <T> 在C#中使用Linq到SQL - Convert Anonymous Type to List <T> using Linq to SQL in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM