在C#中获取字符串的方法有很多种,可以使用字符串字面值、字符串变量、字符串连接、字符串格式化等。下面是一些常用的方法:
string str = "Hello, World!";
string str1 = "Hello";
string str2 = "World";
string str = str1 + ", " + str2 + "!";
string str1 = "Hello";
string str2 = "World";
string str = string.Concat(str1, ", ", str2, "!");
string str = string.Format("Hello, {0}!", "World");
Console.WriteLine("请输入字符串:");
string str = Console.ReadLine();
这些是一些获取字符串的基本方法,具体使用哪种方法取决于具体的情况和需求。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c#怎么获取字符串中某个字符