Search code examples
c#charcapitalize

Capitalize a single 'char'acter in C#?


Is there a "simple" way to capitalize a single char-typed value?

This will work, but feels cumbersome and generally wrong:

var ch = 'a';
var cap = ("" + ch).ToUpper()[0];
cap.Dump(); // (in LINQPad) => 'A'

Notes:

  1. The choice of "" + ch over ToString() is because ReSharper yells at me for not specifying a culture with the latter ... in any case, ch.ToString().ToUpper()[0] feels just as cumbersome.
  2. For the sake of globalization, just "adding 32" is not an option; I do not believe there is any single char that turns into a surrogate-pair when capitalized.

Thanks,


Solution

  • Char.ToUpper(ch)
    

    should do the job.