Return array from function.

Assuming that you want to return an array of strings then the following sample shows one method:

Dictionary<string, int> listOfServers = new Dictionary<string, int>();
listOfServers.Add("Server 1", 123980123);
listOfServers.Add("Server 2", 123234235);
string[] results = listOfServers.Select (x => x.Key).ToArray();

where the int part of the listIfServers stands for the Servers type. For you example above it would be simply

return listOfServers.Select (x => x.Key).ToArray();

Otherwise change the signature of your method to the Dictionary<string, Servers> return type.

Browse More Popular Posts

Leave a Comment