data[,] 到 List 或 List 中 C# 中

本文关键字:List object data string | 更新日期: 2023-09-27 18:37:06

我有一个二维数组object[,] data; .我想将对象的第一列转换为list<string>list<object>。这里有我的代码:

List<string> resultsFields = new List<string>();
object tmp = oRtx.get_ListFields(this.Instrument.ElementAt(i).Key.ToString(), RT_FieldRowView.RT_FRV_EXISTING, RT_FieldColumnView.RT_FCV_VALUE);
if (tmp != null)
{
    object[,] data = (object[,])Convert.ChangeType(tmp, typeof(object[,]));
    for (int j = 0; j < numItems; j++)
         resultsFields.Add(data[j, 0].ToString());
}

在此代码中,我将data[j, 0]上的每个项目添加到我的列表中。我想知道是否有更快的方法将对象的第一列([0])转换为列表

data[,] 到 List<string> 或 List<object> 中 C# 中

我能看到的唯一性能改进是创建具有指定容量的列表<>:

List<string> resultsFields = new List<string>(data.GetLength(0));
相关文章: