How to convert list to string in C#?

王林
Release: 2023-08-30 23:29:10
forward
1015 people have browsed it

如何在 C# 中将列表转换为字符串?

Declare a list.

List < string > l = new List < string > ();
Copy after login

Now, add the elements to the list.

// elements l.Add("Accessories"); l.Add("Footwear"); l.Add("Watches");
Copy after login

Now convert it to string.

string str = string.Join(" ", l.ToArray());
Copy after login

Let’s see the final code in C# to convert list to string -

Example

using System; using System.Collections.Generic; class Demo { static void Main() { List < string > l = new List < string > (); // elements l.Add("Accessories"); l.Add("Footwear"); l.Add("Watches"); string str = string.Join(" ", l.ToArray()); Console.WriteLine(str); } }
Copy after login

The above is the detailed content of How to convert list to string in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!