How to implement IEnumerable <int> from this C # code?

I am trying to convert this C # code to C ++ / cli code:

class MyRange : IEnumerable<int> { public IEnumerator<int> GetEnumerator() { return null; } IEnumerator IEnumerable.GetEnumerator() { return null; } } 

Here is my attempt:

 namespace Tests { public ref class MyRange : System::Collections::Generic::IEnumerable<int> { private: virtual System::Collections::IEnumerator^ GetEnumerator() = System::Collections::IEnumerable::GetEnumerator { return nullptr; } virtual System::Collections::Generic::IEnumerable<int>^ GetEnumerator() { return nullptr; } }; } 

This gives me so many errors (like 20), that I don’t even think it’s worth putting them here.

I have been looking for all this and it looks like many people have the same problem as me.

+4
source share
2 answers

Well, after a lot of fighting, I found some working code:

 namespace Tests { ref class MyCollection : public Generic::IEnumerable<int> { public: virtual System::Collections::IEnumerator^ GetEnumeratorNonGeneric() = System::Collections::IEnumerable::GetEnumerator { return GetEnumerator(); } virtual Generic::IEnumerator<int>^ MyCollection::GetEnumerator() { return nullptr; } }; } 
+4
source

It is often useful to parse your C # in Reflector using Managed C ++ as the target language, and then translate to C ++ / CLI.

+2
source

All Articles