开发者

What does this C# code mean? [closed]

开发者 https://www.devze.com 2023-01-02 21:02 出处:网络
Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code nece
Closed. This question needs debugging details. It is not currently accepting answers.

Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.

Closed 8 years ago.

Improve this question
Fu开发者_C百科nctionThatReturnsAList(cmd)[0]


It is short-hand for:

List<Whatever> list = FunctionThatReturnsAList(cmd);
Whatever whatever = list[0];


The return type of FunctionThatReturnsAList is an object, like a List or an array that can be accessed via an indexer. The code is calling the function, which is then returning the List or array and then using the indexer to reference the first element in the collection.

An example would be:

var cmd = "123";

var returnedObj = FunctionThatReturnsAList(cmd)[0];

private List<string> FunctionThatReturnsAList(cmd)
{
    return new List<string> {cmd};
}


The function returns a list, and you just access element 0 in the returned list.


Seems like cmd is an SQL command which returns may be array of some kind like DataTable[] and this function gets only first element(DataTable) from the array.


This statement can be used for all methods whose return type has a numeric indexer (e.g. lists or arrays).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号