convert C# code to LINQ

Posted by Oswaldlily under ASP.NET on 4/26/2016 | Points: 10 | Views : 197 | Status : [Member] | Replies : 1
How to convert this code into simple LINQ

for (int i= 1; i< DataTable.Rows.Count; i++)
DataRow row = AnotherDataTable.NewRow();
for (int j= 0; j< DataTable.Columns.Count; j++)
row[j]= CommonFunction(DataTable.Rows[i][j], AnotherDataTable.Columns[j].DataType);


Posted by: Sheonarayan on: 4/26/2016 [Administrator] HonoraryPlatinum | Points: 25

I think understanding LINQ is important before answering this question.

Any C# code can't be converted into LINQ, LINQ stands for Language Integrated Query, ie. it is the query language to query the object collection. In your case it is also a collection of DataRow (DataTable) however you are a function CommonFunction within the inner loop and this is not possible to call within a LINQ query (as far as I know).

So to sum up, above code can't be converted into LINQ.


Sheo Narayan

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response