i have a SortableList<T> class that implements ISortable<T>. I am having hard time to implement below two members of interface..

public IEnumerator GetEnumerator() { //Is this right? return this.List.GetEnumerator(); } #endregion #region IEnumerable<T> Members IEnumerator<T> IEnumerable<T>.GetEnumerator() { // how i am gona implement it? } 

and here is the code for whole class . Any help will be appreciated

public class SortedList<T> : ISortable<T> { public List<T> List { get; private set; } public string Sort { get; private set; } public string Order { get; private set; } public SortedList(List<T> list, string sort = null, string order = null) { List = list; Sort = sort; Order = order; } public IEnumerator GetEnumerator() { } IEnumerator<T> IEnumerable<T>.GetEnumerator() { } } 

And ISortable is here

public interface ISortable : IEnumerable { string Sort { get; } string Order { get; } } 

and here is ISortable of T

public interface ISortable<T> : ISortable, IEnumerable<T> { // No members.. } 
2

1 Answer

You implement all that both methods by doing something like this:

public IEnumerator GetEnumerator() { return ((IEnumerable<T>) this).GetEnumerator(); } IEnumerator<T> IEnumerable<T>.GetEnumerator() { return this.List.GetEnumerator(); } 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.