Để chuyển đổi chuỗi từ chữ thường sang chữ hoa trong C#, bạn sử dụng phương thức ToUpper().
Ví dụ, giả sử chuỗi của bạn là:
str = "david";
Để chuyển chuỗi chữ thường trên thành chữ hoa:
Console.WriteLine("Chuyển thành chữ hoa: {0}", str.ToUpper());
Ví dụ hoàn chỉnh
using System;
using System.Collections.Generic;
using System.Text;
namespace Demo {
class MyApplication {
static void Main(string[] args) {
string str;
str = "david";
Console.WriteLine("Chữ thường: {0}", str);
// chuyển sang chữ hoa
Console.WriteLine("Chuyển thành chữ hoa: {0}", str.ToUpper());
Console.ReadLine();
}
}
}