tags:

views:

56

answers:

3

ASP.NET/C# 3.0

I have a method which has the following signature:

public static void SendEmail(string sFrom, string sSubject, string sBody, params string[] sAddresses)

I need to loop through a dataset checking the value of column2. If the value of column2 is True, the string value from column1 should be added to the sAddresses string[].

The only way I know of is to resize the string[] +1 with every iteration. This doesn't sound very efficient. Shirley there's a better way.

Thanks! Kevin

+5  A: 

Use a List<string> and add the items there. When you're done, call ToArray to get the string array back.

Otávio Décio
+3  A: 

By default I jump to Linq. It may not be the best, though:

string[] addresses = (from row in table.Rows
                      where ((bool)row[2])
                      select (string)row[1]).ToArray()
Talljoe
A: 

That was the kind of solution I was looking for. I knew it had to exist. Thanks!

(Shirley you can't be serious)

Kevin
Stop calling me Shirley.
Talljoe
Sorry. Figured someone would get the reference. Carry on.
Kevin