C++ CLI .NET core 5 function returning IEnumerable

Arathi Jinde 6 Reputation points
2021-04-19T06:44:12+00:00

Hi
how to return IEnumerable from a C++/CLI .NET Core library in a function
List<MyClass> li = gcnew List<MyClass>();

IEnumerable<MyClass^>^ Find(String^ key)
{
// how to return from list
}

Also Task/await is not supported in C++/CLI core dll what is the alternative to implement in a function

the below implementation is not possible as this is unsupported in C++/CLI what is the alternative to this , please suggest
Task <IEnumerable<MyClass^>> ^ Find(String^ key)
{
return Task.CompletedTask
}

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
316 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,482 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 8,771 Reputation points Microsoft Vendor
    2021-04-20T09:23:32.293+00:00

    Hi,

    If you want to return IEnumerable, I suggest you should try to use FindAll instead of Find. And you'll need to use a delegate explicitly.

    For example:

    bool IsAge(MyClass^ item)   
    {  
    	return item->Age == 12;  
    }  
      
    IEnumerable<MyClass^>^ result = list->FindAll(gcnew System::Predicate<MyClass^>(IsAge));  
    

    Could you please provide more details about the second question? What do you want to achieve?

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.