-1

I have a datatable which holds some Id. I want to extract those Id's with comma seperated values. What I tried is:

With LINQ

int [] strGoalIds = (from Task in dtActionItems.AsEnumerable()
                    select Task.Field<int>("TaskEntityId")).ToArray(); 
string strGoalTagIds = "";
if (strGoalIds.Count() > 0)
{
  strGoalTagIds = string.Join(",", strGoalIds );
}

WITH For Loop

string strGoalIds = "";
for (int i = 0; i < dtActionItems.Rows.Count; i++)
{
  strGoalIds = strGoalIds + "," + dtActionItems.Rows[i]["TaskEntityId"].ToString();
}

Can anyone tell me which is the best way to proceed.

nrsharma
  • 2,532
  • 3
  • 20
  • 36
  • possible duplicate of [For vs. Linq - Performance vs. Future](http://stackoverflow.com/questions/14893924/for-vs-linq-performance-vs-future) – Saghir A. Khatri May 06 '14 at 07:14

1 Answers1

1

Performance wise LINQ is slower, as LINQ internally use loops. If you are really working for perfomance go with the for loop. This stack overflow Post might help you For vs. Linq - Performance vs. Future

Community
  • 1
  • 1
Saghir A. Khatri
  • 3,429
  • 6
  • 45
  • 76