在C#中,字符串可以通過以下幾種方式進行創建和初始化:
string str = "Hello, World!";
string str1 = "Hello, ";
string str2 = "World!";
string result = str1 + str2;
string name = "Alice";
int age = 30;
string message = $"My name is {name} and I am {age} years old.";
string str = new string('a', 5); // 創建包含5個字符'a'的字符串