0

所以,我有以下代码

int[] GetIndexes(string columns)
{
  ...
}

var indexes = GetIndexes("Code|Name|Description");
var codeIndex = indexes[0];
var nameIndex = indexes[1];
var descIndex = indexes[2];

最好以下面的方式使用它:

GetIndexes("Code|Name|Description", ref codeIndex, ref nameIndex, ref descIndex);

你有什么建议吗?

4

1 回答 1

0

您可以使用自己的类来获取索引。怎么看:

class IndexReceiver
{
    public string Name { get; set; }
    public int Index { get; set; }

    public static implicit operator IndexReceiver(string name)
    {
        return new IndexReceiver() { Name = name };
    }
}

然后,您像这样定义您的方法:

void GetIndexes(params IndexReceiver[] receivers)
{
    // Here you read the each IndexReceiver's Name property and write the index.
}

像这样使用新方法:

IndexReceiver code = "Code", index = "Index", desc = "desc"
GetIndexes(code, index, desc);
于 2013-05-13T12:24:36.497 回答