Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8178547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:47:35+00:00 2026-06-06T23:47:35+00:00

i got a code for converting datatable to ilist. which may work but the

  • 0

i got a code for converting datatable to ilist. which may work but the code not very clear to me. here is code

table.AsEnumerable()
.Select(r => table.Columns.ToDictionary(c => c.ColumnName, c => r[c]))
.ToList();

what is table.Columns.ToDictionary()…what it does. what is the meaning of c => c.ColumnName, c => r[c]
what r[c] return. not very clear to me.

i got a another snippet….here it is

var list = new List<DataRow>();
foreach (var row in table.Rows)
   list.Add(row);

return list;

this code is clear to me but i want to know which code has good performance out of 2 different snippet. please discuss. thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:47:37+00:00Added an answer on June 6, 2026 at 11:47 pm

    The ToDictionary call converts each DataRow to a Dictionary<string, object> which you can use to find the value of any field within the row. => is the syntax used in a lambda expression – you should really learn about lambda expressions if you’re going to do any significant amount of work with LINQ.

    Your second snippet would be more simply written as:

    var list = table.Rows.Cast<DataRow>().ToList();
    

    In terms of efficiency – the first form fetches all the data from the row as it builds the dictionary. That’s likely to make it less efficient if you only need to look at some of the fields. On the other hand, it may be more convenient. It depends on what you do with it later. In terms of memory, the second form will mean the DataRow objects themselves can’t be garbage collected, whereas the first form doesn’t need the rows afterwards – but it’s created a copy of all the actual data. Whether that’s relevant in your situation will again depend on the rest of your code.

    I wouldn’t focus on the performance to start with though – start off with whichever code makes the rest of your application simplest to write, then check whether that performs well enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From a DB2 table I've got blob which I'm converting to a byte array
I've got some C# code that I'm converting to Objective-C. In C# I would
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
i got a code for calling a function until meet the condition but i
I've got a little problem here. I'm converting binary to ascii, in order to
i'm converting code project from Flash AS 3 to Flex 4. I've got a
I've got the following piece of code which exectues within no problem SELECT (
this code compiles in Linux but not Solaris, because apparently ppoll() is Linux specific
I have a Objective C code,which I have to translate in Java,but I have
I ran a perl script in biotoolbox package.(http://code.google.com/p/biotoolbox/) but got the error message related

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.