Linux 拨号vps windows公众号手机端

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

lewis 7年前 (2018-04-02) 阅读数 9 #程序编程
文章标签 c#

在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"
版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门