Reputation: 23749
Question: Without using a foreach
loop how we can find out if a StorageFolder has any SubFolder
. Probably a C#
guru can help here.
Why asked: I am using StorageFolder.GetFoldersAsync() method that returns IAsyncOperation<IReadOnlyList<StorageFolder>>
and does seem to have IReadOnlyCollection.Count property but I could figure out how to use this property in my following line of code. I do need that count and do not want to use foreeach
loop to get that count - unless there is not better work around:
......
IAsyncOperation<IReadOnlyList<StorageFolder>> MyList = MyStorageFolder.GetFoldersAsync();
......
So, how do I apply count
property to MyList
Upvotes: 0
Views: 241
Reputation: 8591
how do I apply count property to MyList
So, you did not know how to call an asynchronous method. Please see The Task asynchronous programming model in C# and Asynchronous programming in the UWP for details.
For your question, you just need to change your code like the following:
private async void YourMethod()
{
......
IReadOnlyList<StorageFolder> MyList = await MyStorageFolder.GetFoldersAsync();
if (MyList.Count > 0)
{
Debug.WriteLine("SubFolder exists.");
}
}
Upvotes: 1