Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# list to string

List<string> names = new List<string>() { "John", "Anna", "Monica" };
string result = string.Join(",", names.ToArray());
Comment

c# convert list to string

string combindedString = string.Join( ",", myList.ToArray() );
Comment

list of string to string c#

string Something = string.Join(",", MyList);
Comment

list of list of string to list of string c#

input.SelectMany(l => l).Distinct().ToList();
Comment

list object into string c#

var combined = string.Join(", ", myObjects);
Comment

c# list to string

using System.Linq;
string str = list.Aggregate((x, y) => x + ',' + y);
Comment

c# convert list to string and back

public static class UsersConverter
{
    // Separates user properties.
    private const char UserDataSeparator = ',';

    // Separates users in the list.
    private const char UsersSeparator = ';';

    public static string ConvertListToString(IEnumerable<User> usersList)
    {
        var stringBuilder = new StringBuilder();

        // Build the users string.
        foreach (User user in usersList)
        {
            stringBuilder.Append(user.Name);
            stringBuilder.Append(UserDataSeparator);
            stringBuilder.Append(user.Age);
            stringBuilder.Append(UsersSeparator);
        }

        // Remove trailing separator.
        stringBuilder.Remove(stringBuilder.Length - 1, 1);

        return stringBuilder.ToString();
    }

    public static List<User> ParseStringToList(string usersString)
    {
        // Check that passed argument is not null.
        if (usersString == null) throw new ArgumentNullException("usersString");

        var result = new List<User>();

        string[] userDatas = usersString.Split(UsersSeparator);

        foreach (string[] userData in userDatas.Select(x => x.Split(UserDataSeparator)))
        {
            // Check that user data contains enough arguments.
            if (userData.Length < 2) throw new ArgumentException("Users string contains invalid data.");

            string name = userData[0];
            int age;

            // Try parsing age.
            if (!int.TryParse(userData[1], out age))
            {
                throw new ArgumentException("Users string contains invalid data.");
            }

            // Add to result list.
            result.Add(new User { Name = name, Age = age });
        }

        return result;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# datagridview column size 
Csharp :: c# get last item in list 
Csharp :: unity ignore collision between two objects 
Csharp :: unity rotation 
Csharp :: unity get all components in gameobject 
Csharp :: c# 
Csharp :: how to make multiplayer game in unity 
Csharp :: c# get offset from timezone 
Csharp :: unity c# 
Csharp :: error provider c# 
Csharp :: default generic parameter for method in c# 
Csharp :: how to print dictionary in c# 
Csharp :: c# check if 2d array position exists 
Csharp :: cannot convert string to generic type c# 
Csharp :: c# array 
Csharp :: what is a protected int c# 
Csharp :: unity detect keyboard not mouse 
Csharp :: unity log warning 
Csharp :: where did mark twain go to school 
Csharp :: disable rigidbody unity 
Csharp :: c# distinct by property 
Csharp :: c# csv read write 
Csharp :: convert list to ienumerable 
Csharp :: httpwebrequest c# example 
Csharp :: foreach enum 
Csharp :: get width of image unity 
Csharp :: HOW TO RETURN CELL VALUE FROM EXCEL IN C# 
Csharp :: c# read lines number 3 from string 
Csharp :: Pass Querystring in C# httpclient 
Csharp :: c# int array 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =