Hi guys i did some code to get list of databases that exists in mongodb server. the list is stored in lst i want to make the function give back a result so i used out . here is the first method it works fine
public static async void listDatabases()
{
List<string> lst = null;
try
{
MongoClient client = new MongoClient("mongodb://127.0.0.1:27017");
//MongoServer server = client.GetServer();
// List<string> lstdatabases = server.GetDatabaseNames().ToList();
using (var cursor = client.ListDatabasesAsync())
{
await cursor.Result.ForEachAsync(d => lst.Add(d.GetElement(0).Value.ToString()));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
and here what i tried to make the function return value
public static async void listDatabases(out List<string> lstListDB)
{
List<string> lst = null;
try
{
MongoClient client = new MongoClient("mongodb://127.0.0.1:27017");
//MongoServer server = client.GetServer();
// List<string> lstdatabases = server.GetDatabaseNames().ToList();
using (var cursor = client.ListDatabasesAsync())
{
await cursor.Result.ForEachAsync(d => lst.Add(d.GetElement(0).Value.ToString()));
lstListDB = lst;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
lstListDB = null;
}
}
it said i can't use out with async method any help thanks
>`. [Why you can't use `out`](http://stackoverflow.com/questions/18716928/how-to-write-a-async-method-with-out-parameter)
– Tim Schmelter Apr 13 '17 at 09:55> i couldn't do it ,any help please am just new
– Maher HTB Apr 13 '17 at 09:57