Nithish Kumar
Nithish Kumar

Reputation: 37

How to parse or extract data from "System.Collections.Generic.List`1[Microsoft.Online.Administration.UserLicense]" object in c#

I'm writing a console application that displays all the user's license information in my tenant. When I tried to print, It's printing like "System.Collections.Generic.List`1[Microsoft.Online.Administration.UserLicense]". How to parse data from it using c#?

     foreach (PSObject result in PS.Invoke())
            {
                foreach (var member in result.Members)
                {
                     if (member.Name == "Licenses")
                    {
                            Console.WriteLine(member.Value);
                    }
                };
            }

Upvotes: 0

Views: 945

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174825

List`1 (or List<T> if you will) implements IEnumerable, so an extra foreach loop to iterate through the values will do:

foreach (PSObject result in PS.Invoke())
{
    foreach (var member in result.Members)
    {
        if (member.Name == "Licenses")
        {
            foreach (var license in member.Value)
            {
                // license is now an individual `UserLicense` object
            }
        }
    }
}

Upvotes: 1

Related Questions