0

I have a array of two dimensions object[,] data;. I want to convert the first column of my object into a list<string> or a list<object>. here you have my code :

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());
}

in this code, I add each items on data[j, 0] into my list. I would like to know if there is a faster method to convert the first column of my object ([0]) into a list


The only performance improvement i can see is creating the List<> with the specified capacity:

List<string> resultsFields = new List<string>(data.GetLength(0));
4

1 に答える 1

2

私が見ることができる唯一のパフォーマンスの向上は、指定された容量でList<>を作成することです。

List<string> resultsFields = new List<string>(data.GetLength(0));
于 2012-06-14T15:02:29.287 に答える