在C#中,可以使用ToLower()方法将字符串转换为小写,使用ToUpper()方法将字符串转换为大写。示例如下:
string str = "Hello, World!";
string upperStr = str.ToUpper();
string lowerStr = str.ToLower();
Console.WriteLine("原始字符串:" + str);
Console.WriteLine("转换为大写:" + upperStr);
Console.WriteLine("转换为小写:" + lowerStr);
输出结果为:
原始字符串:Hello, World!
转换为大写:HELLO, WORLD!
转换为小写:hello, world!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:C#中字符串的大小写转换技巧