none
Trying to convert an IEnumerable<Guid?> to a IList<Guid> but cannot find proper documentation. RRS feed

All replies

  • Greetings Joey.

    I don't understand the question. There's nothing on that line that tries to convert an IEnumerable to an IList. What exactly is the error you are getting?

    Tuesday, July 9, 2019 11:20 PM
  • Hi Joey,

    Thank you for posting here.

    Since this thread is related to Azure, we don't support it. I suggest that you could send the feedback in the link you provided.

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 10, 2019 5:47 AM
  • Hello,

    all you have is to use Select method to project the result in List<Guid> :

    var ids = faceIds
       .Where(r => r.HasValue) // here we filter the list based on the HasValue property    
       .Select(r => r.Value).ToList<Guid>(); 
    var results = await faceClient.Face.IdentifyAsync(ids, personGroupId);


    Best regards;


    Wednesday, July 10, 2019 8:40 AM
  • So `FaceClient.Face.IdentifyAsync` requires an IList<Guid> as the first parameter but your `faceIds` variable is of type `IEnumerable<Guid>`? To convert an `IEnumerable<Guid>` to `List<Guid>` (which implements `IList<Guid>`) use the `ToList` method from LINQ.

    var results = await faceClient.Face.IdentifyAsync(faceIds.ToList(), personGroupId);
    Note that you should only use `ToList` when you need an actual list and/or you need to force enumeration of the results (aka coming back from a database call).



    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, July 10, 2019 2:08 PM
  • My apologies the question was a little ambiguous,

    The identifyAsync() requires faceIds to be an IList<Guid>, however the tutorial autotypes faceIds to an Guid?[]. I get an error when I try to run this code. What suggestions do y'all have to fix this? 

    I tried the above suggestion from Cherkaoui.Mouad and It is still giving me an error, for it is not letting me add the <Guid> to ToList(), for it takes the same type it was applied to. 

    Wednesday, July 10, 2019 2:10 PM
  • I got everything working. Thanks to everyone for the help!
    Wednesday, July 10, 2019 2:22 PM
  • Hi, 

    I think that you should add using for :

    using System.Linq;
    using System.Collections.Generic;

    anyway it should work with ToList() since the projected value is a Guid.

    Good Coding;

    Wednesday, July 10, 2019 3:12 PM