Join custom objects into a concatenated string in .NET C#

Say you have the following Customer object with an overridden ToString method:

public class Customer
{
	public int Id { get; set; }
	public string Name { get; set; }
	public string City { get; set; }

	public override string ToString()
	{
		return string.Format("Id: {0}, name: {1}, city: {2}", Id, Name, City);
	}
}

Read more of this post

Advertisement

6 ways to concatenate strings with C# .NET

There are multiple ways to build a string out of other strings in .NET. Here come 5 of them.

Let’s start with the most obvious one that language learners encounter first, i.e. concatenation done by the ‘+’ operator:

string concatenatedOne = "This " + "is " + "a " + "concatenated " + "string.";

Read more of this post

5 ways to concatenate strings with C# .NET

There are multiple ways to build a string out of other strings in .NET. Here come 5 of them.

Let’s start with the most obvious one that language learners encounter first, i.e. concatenation done by the ‘+’ operator:

string concatenatedOne = "This " + "is " + "a " + "concatenated " + "string.";

Read more of this post

5 ways to concatenate strings with C# .NET

There are multiple ways to build a string out of other strings in .NET. Here come 5 of them.

Let’s start with the most obvious one that language learners encounter first, i.e. concatenation done by the ‘+’ operator:

string concatenatedOne = "This " + "is " + "a " + "concatenated " + "string.";

Read more of this post

Join custom objects into a concatenated string in .NET C#

Say you have the following Customer object with an overridden ToString method:

public class Customer
{
	public int Id { get; set; }
	public string Name { get; set; }
	public string City { get; set; }

	public override string ToString()
	{
		return string.Format("Id: {0}, name: {1}, city: {2}", Id, Name, City);
	}
}

Read more of this post

Concatenate two IEnumerable sequences in C# .NET

We can use the Range method to build two integer sequences as follows:

IEnumerable<int> firstRange = Enumerable.Range(10, 10);
IEnumerable<int> secondRange = Enumerable.Range(5, 20);

You can join the two sequences using the Concat method:

List<int> concatenated = firstRange.Concat(secondRange).ToList();
concatenated.ForEach(i => Debug.WriteLine(i));

You’ll see that the concatenated sequence holds all numbers from the first and the second sequence:

Read more of this post

Join custom objects into a concatenated string in .NET C#

Say you have the following Customer object with an overridden ToString method:

public class Customer
{
	public int Id { get; set; }
	public string Name { get; set; }
	public string City { get; set; }

	public override string ToString()
	{
		return string.Format("Id: {0}, name: {1}, city: {2}", Id, Name, City);
	}
}

Read more of this post

5 ways to concatenate strings with C# .NET

There are multiple ways to build a string out of other strings in .NET. Here come 5 of them.

Let’s start with the most obvious one that language learners encounter first, i.e. concatenation done by the ‘+’ operator:

string concatenatedOne = "This " + "is " + "a " + "concatenated " + "string.";

Read more of this post

Elliot Balynn's Blog

A directory of wonderful thoughts

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Once Upon a Camayoc

Bite-size insight on Cyber Security for the not too technical.

%d bloggers like this: