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 questionFu开发者_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).
精彩评论