如何使用 C# 将小写字母转换为大写字母?

csharpprogrammingserver side programming更新于 2025/5/28 19:07:17

要将小写字母转换为大写字母,请使用 C# 中的 ToUpper() 方法。

假设您的字符串为 −

str = "david";

要将上述小写字母字符串转换为大写字母,请使用 ToUpper() 方法 −

Console.WriteLine("Converted to UpperCase : {0}", str.ToUpper());

以下是 C# 中用于转换字符大小写的代码 −

示例

using System;
using System.Collections.Generic;
using System.Text;

namespace Demo {
   class MyApplication {
      static void Main(string[] args) {

         string str;
         str = "david";
         Console.WriteLine("LowerCase : {0}", str);

         // convert to uppercase
         Console.WriteLine("Converted to UpperCase : {0}", str.ToUpper());
         Console.ReadLine();
      }
   }
}

相关文章