From: Andy O'Neill on

"Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message
news:u$%23qkgdyKHA.2644(a)TK2MSFTNGP04.phx.gbl...
<<>>
>> What happens if one of the entries in an array you use join on is null?
>
> It works fine:
>
> string[] items = new string[] { "Red", "Green", null, "Blue" };
> string output = string.Join(",", items);
>
> produces: Red,Green,,Blue

2 separators.
Depends on what output is required for a null entry.

From: Family Tree Mike on
On 3/22/2010 12:13 PM, Andy O'Neill wrote:
>
> "Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message
> news:u$%23qkgdyKHA.2644(a)TK2MSFTNGP04.phx.gbl...
> <<>>
>>> What happens if one of the entries in an array you use join on is null?
>>
>> It works fine:
>>
>> string[] items = new string[] { "Red", "Green", null, "Blue" };
>> string output = string.Join(",", items);
>>
>> produces: Red,Green,,Blue
>
> 2 separators.
> Depends on what output is required for a null entry.
>

// Looks like my last sent message errored out on the server.

Yes, whether it works, depends on your definition of works. :)

What I meant was, it produces a string, that when run through
string.split(), faithfully reproduces the input list of strings.


--
Mike
From: Arne Vajhøj on
On 22-03-2010 13:15, Family Tree Mike wrote:
> On 3/22/2010 12:13 PM, Andy O'Neill wrote:
>> "Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message
>> news:u$%23qkgdyKHA.2644(a)TK2MSFTNGP04.phx.gbl...
>>>> What happens if one of the entries in an array you use join on is null?
>>>
>>> It works fine:
>>>
>>> string[] items = new string[] { "Red", "Green", null, "Blue" };
>>> string output = string.Join(",", items);
>>>
>>> produces: Red,Green,,Blue
>>
>> 2 separators.
>> Depends on what output is required for a null entry.
>
> // Looks like my last sent message errored out on the server.

I got it.

>
> Yes, whether it works, depends on your definition of works. :)
>
> What I meant was, it produces a string, that when run through
> string.split(), faithfully reproduces the input list of strings.

And if the empty element is not wanted then there is the
option of:

string output = items.Aggregate((tot,nxt) => tot + (nxt != null ? "," +
nxt : ""));

Arne