Question: A little newbie question. I have a foreach loop where I am trying to access the property of a row object and assign to a string.

```
foreach(row in Dataset)
{
 string finalName= row.name;

}

```

On each iteration I need to concat each row's name property to the finalName 

\Thanks alot,

Answer: 
Depending on your performance requirements you can either concat using the addition operator:

```
string finalName = string.Empty;
foreach(row in Dataset)
{
    finalName += row.name;    
}

```

or use a [StringBuilder](http://msdn.microsoft.com/en-us/library/2839d5h5(VS.71).aspx):

```
Stringbuilder sb = new StringBuilder();
foreach(row in Dataset)
{
    sb.Append(row.Name);   
}

string finalName = sb.ToString();

```

General for very small numbers of appends you won't notice a difference between the two versions. But if you are combining a lot of strings then there may be a very noticeable performance and memory benefit to using the StringBuilder.

Also bear in mind that this will place the strings directly one after the other so you may also wish to append a space or new line between each of them.

---

Special bonus LINQ one-liner:

Since you seem to be new to C# I'd suggest that you ignore this one since it is quite advanced and frankly not as readable (but on the other hand who doesn't like throwing random bits of LINQ into their code?). Still, I'll add it here for completeness. I don't know what the performance is like, but one major advantage over the other methods is the ease with with you can place a space or other character between the strings. Just change the value in the marked line to whatever value you want to separate the combined strings with (Environment.NewLine or " ", for example)

```
string finalName = string.Join(
                "", //Change the value here to separate the strings.
                (from row in Dataset
                 select row.Name).ToArray());

```

or, if you prefer lambdas to LINQ:

```
string finalName = string.Join(
            "", //Change the value here to separate the strings.
            Dataset.Select(row => row.Name).ToArray());

```
Here's one...

```
string finalName = ""

foreach (DataRow row in dataSet.TableX)
{
   finalName += row.Name;
   finalName += Environment.NewLine;
}

```

Here's another...

```
StringBuilder finalName = new StringBuilder()

foreach (DataRow row in dataSet.TableX)
{
    finalName.Append(row.Name);
    finalName.Append(Environment.NewLine);
}

```