Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get last alphabetic value without using lists

I have some strings, and I would like to get the letter that is last in alphabetic order.
I know how to do it on a List (ordering the list), but what I would like is such a function :

private string getLastValue(string a, string b)
{
   //????
}

getLastValue("a","b") may return "b"

getLastValue("azerty","qwerty") may return "qwerty"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can just compare strings with a help of StringComparer, e.g.

private string getLastValue(string a, string b) =>
    StringComparer.Ordinal.Compare(a, b) > 0 ? a : b;

Note, that you can choose the comparer required: Ordinal, OrdinalIgnoreCase etc.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading