سؤال

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,

هل كانت مفيدة؟

المحلول

Char.ToUpper(ch)

should do the job.

نصائح أخرى

try Char.ToUpper()

var a = 'a';
a = Char.ToUpper(a);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top