LINQ select one field from list of DTO objects to array

后端 未结 5 638
我寻月下人不归
我寻月下人不归 2020-12-05 02:31

I have DTO class that defines order line like this:

public class Line
{
    public string Sku { get; set; }
    public int Qty    { get; set; }
}
         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 02:50

    You can select all Sku elements of your myLines list and then convert the result to an array.

    string[] mySKUsArray = myLines.Select(x=>x.Sku).ToArray();
    

提交回复
热议问题