1

Was trying to implement sorting of a List<string> in a custom way. Implemented the IComparer<string> interface, and it worked well. But after experimenting more with the Sort method of the list, I observed that this also works

list.Sort((s, s1) => {return s.ToLower().CompareTo(s1.ToLower()); });

But the MSDN documentation says nothing about the acceptance of a delegate as a parameter in the Sort method,neither the Intellisense shows an overload of this method which accepts a delegate.

So I would like to ask, that how did it worked?

1

1 Answer 1

4

You invoked the overload that takes a Comparison<T> as an argument.

Comparison<T> is a delegate type, so the lambda function you provided fits the bill just right.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.