租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

c#中concat函数的用法是什么,c# conditional

发布时间:2024-03-26 16:56:52

c#中concat函数的用法是甚么

在C#中,Concat()函数用于连接两个或多个字符串,并返回一个新的字符串。该函数可以接受任意数量的字符串作为参数,将它们依照参数的顺序连接起来。下面是Concat()函数的用法示例:

string str1 = "Hello";
string str2 = "World";
string result = string.Concat(str1, str2);

Console.WriteLine(result); // 输出结果为 "HelloWorld"

除连接字符串以外,Concat()函数还可以连接其他类型的对象,它会将这些对象的ToString()方法返回的结果转换为字符串并连接起来。例如:

int num1 = 10;
double num2 = 20.5;
string result = string.Concat("The numbers are: ", num1, " and ", num2);

Console.WriteLine(result); // 输出结果为 "The numbers are: 10 and 20.5"