【问题标题】:How to get list object in Array in asp.net?如何在asp.net的数组中获取列表对象?
【发布时间】:2017-10-26 07:38:06
【问题描述】:

我有 List 它包含项目名称和数量。

如何从 Label[] lblItemName 数组中的 List 中获取项目名称和 Label [] lblQuantity 数组中的数量? 是否可以将这些值存储在单独的数组中?

【问题讨论】:

标签: c# asp.net arrays list


【解决方案1】:

您可以执行以下操作:

var IbItemName = yourList.Select(x=> new Label { Text = x.Name}).ToArray();
var IbIQuantity = yourList.Select(x=> new Label { Text = x.Quantity.ToString()}).ToArray(); 

这种方法会更快:

Label[] IbItemName = new Label[YourList.Count];
Label[] IbIQuantity = new Label[YourList.Count];
for(int i = 0; i < YourList.Count; i++){
   IbItemName[i] = new Label { Text = YourList[i].Name };
   IbIQuantity[i] = new Label { Text = YourList[i].Quantity.ToString() };
}

【讨论】:

    猜你喜欢
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    • 2020-09-02
    • 2019-04-12
    • 1970-01-01
    • 2019-09-11
    • 2015-07-29
    相关资源
    最近更新 更多