Click here to Skip to main content
15,860,972 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

How to Toggle String Case in .NET

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
14 Feb 2011CPOL 6.6K   2   1
What about this?string s = new string(( from c in "ABCdef" select char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c) ).ToArray());Note by Alexander Bell: In regards to the performance, this one (i.e. Alternate 9) is the worst in comparison...
What about this?

string s = new string((
            from c in "ABCdef" 
            select char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c) 
           ).ToArray());


Note by Alexander Bell: In regards to the performance, this one (i.e. Alternate 9) is the worst in comparison with Alternate 1 and Alternate 2, also it requires Linq Library, which negatively impacts the Algorithm portability: Alternate 9 is NOT RECOMMENDED

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
New Zealand New Zealand
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralThis one is actually Alternate 8 Pin
DrABELL16-Feb-11 6:28
DrABELL16-Feb-11 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.