tags:

views:

201

answers:

5
functionwhoreturnlist(cmd)[0]
+10  A: 

It is short-hand for:

List<Whatever> list = functionwhoreturnlist(cmd);
Whatever whatever = list[0];
Dean Harding
A: 

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.

Shoaib Shaikh
WOW!!!! That is impressive! Now quickly, what lottery numbers are coming up next week?
Sani Huttunen
+1  A: 

The return type of functionwhoreturnlist 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 = functionwhoreturnlist(cmd)[0];

private List<string> functionwhoreturnlist(cmd)
{
    return new List<string> {cmd};
}
lomaxx
A: 

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

schaermu
+2  A: 

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

Marthinus