i have a few classes that i am trying to move to using generics
Class1: Curve
this class has the following code:
public class Curve : IEnumerable
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator(); // Calls non-interface method
}
public RTRatePointEnumerator GetEnumerator()
{
return new RTRatePointEnumerator(_hash);
}
Class 2:
public class CurvePointEnumerator : IEnumerator
what is the recommended conversion of these two classes to using generics
Best Solution
You didn't specify the type being returned from the enumerator. but I'm going to guess based on the names it's RTRatePoint and CurvePoint. I would change the code to be the following
One item that may trip you up is that IEnumerator<T> additionally implements IDisposable so CurvePointEnumerator and RTRatePointEnumerator will need to have a Dispose method added. Likely though this method can be pretty much empty. Reason being if you weren't disposing anything before, there's no need to now.