String Swap-case one-liners (6 ways) I did this small project where there are six one-liner anonymous methods that can swap case of a given string of any length. For example "heLLo, woRLd" ==> "HEllO, WOrlD". I used this string as the example to demonstrate how each of the function works. This string "heLLo, woRLd" can simply be replaced with Console.ReadLine() to get user anticipated inputs. I understand one-liners are not readable and maybe not considered good practice, and used variable names are not proper as well. This whole project was for fun. I believe that way I can learn more. My expectation is that someone can tell me if there are more ways to do this case-swapping (of course, has to be one-liner)?. I think I used 3 (kinda) algorithms to do the swapping. Moreover, all of the one-liners are void functions and all the succeeding functions are shorter than the preceding ones.

using System;
using System.Linq;

class x
{
    static void Main(string[] args)
    {
        // one-liner string swapcase
        (new Action&lt;string&gt;(delegate (string x) { foreach (char i in x) { char b = i; b^= char.IsLetter(b) ? (char)32 : (char)0; Console.Write(b); } }))("heLLo, woRLd");

        Console.WriteLine();

        //one-liner string swapcase2
        (new Action&lt;string&gt;(delegate (string x) { foreach (char i in x) { Console.Write(char.IsUpper(i) ? char.ToLower(i) : char.ToUpper(i)); } }))("heLLo, woRLd");

        Console.WriteLine();

        // one-liner string swapcase3
        ((Action&lt;string&gt;)(delegate (string x) { foreach (char i in x) { Console.Write(char.IsUpper(i) ? char.ToLower(i) : char.ToUpper(i)); } }))("heLLo, woRLd");

        Console.WriteLine();

        //one-liner string swapcase4
        ((Action&lt;string&gt;)((x) =&gt; { foreach (char i in x) { Console.Write(char.IsUpper(i) ? char.ToLower(i) : char.ToUpper(i)); } }))("heLLo, woRLd");

        Console.WriteLine();

        //one-liner string swapcase5
        "heLLo, woRLd".ToList().ForEach(i =&gt; Console.Write(char.IsUpper(i) ? char.ToLower(i) : char.ToUpper(i)));

        Console.WriteLine();
        //one-liner string swapcase6
        "heLLo, woRLd".ToList().ForEach(i =&gt; Console.Write(i^= char.IsLetter(i) ? (char)(1 &lt;&lt; 5) : (char)0));
        Console.ReadLine();
    }
}
I find your code amusing but since this is not Code Golf but Code Review I'll review it from our perspective this is, as clean-code first.

Even if you try to write compact code you should not use magic exressions and sacrifice readability. Instead encapsulate them in (local) function or use proper constants. You also should not use unrelated variable names like here i for char where c would be more appropriate. Alternatively you can also use the Aggregate to loop over the string and collect the results in a StringBuilder. The (char)0 can be replaced with the much prettier default.

const char caseOffset = (char)(1 &lt;&lt; 5);

char SwapCase(char c) =&gt; c ^= (char.IsLetter(c) ? caseOffset : default);

var result = 
    "heLLo, woRLd"
        .Aggregate(
            new StringBuilder(), 
            (b, c) =&gt; b.Append(SwapCase(c))
        ).ToString();


One more option would be to use Select and new string and feed it with the new result.

var result = new string("heLLo, woRLd".Select(SwapCase).ToArray())


The advantage of Select is that you don't need the =&gt; lambda anymore.