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

  • Home
  • SEARCH
  • 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 6377009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:48:58+00:00 2026-05-25T01:48:58+00:00

Sorry, Im just learning LINQ and am relatively new at it. Is it possible

  • 0

Sorry, Im just learning LINQ and am relatively new at it.

Is it possible to convert the following into LINQ?

foreach (DataRow gradeCount in GraceTable.Rows)
{
    if (Convert.ToDecimal(obtMarksRow["Percentage"]) >= 
        (Convert.ToDecimal(gradeCount["EXG_MARKS_ABOVE"])) &&
        (Convert.ToDecimal(obtMarksRow["Percentage"]) <= 
        Convert.ToDecimal(gradeCount["EXG_MARKS_BELOW"])))
    {
        string Grade = Convert.ToString(gradeCount["EXG_GRADE_NAME"]);
    }
}

Edit : sorry i missed for each loop in ma query and obtMarksRow comes from one more loop which is outside this

I wrote the query like this

     var gradeValue = from DataRow gradeRow in GraceTable.Rows
                                 let marksAbove = gradeRow.Field<decimal>("EXG_MARKS_ABOVE") 
                                 let marksBelow = gradeRow.Field<decimal>("EXG_MARKS_BELOW")
                                 where obtMarksRow.Field<decimal>("Percentage") >= marksAbove && obtMarksRow.Field<decimal>("Percentage") <= marksBelow
                                 select gradeRow.Field<string>("EXG_GRADE_NAME");

but i am getting the value (gradeValue.ToString() ) as “System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Data.DataRow,System.String]”

Whats wrong ?

  • 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-05-25T01:48:59+00:00Added an answer on May 25, 2026 at 1:48 am

    No, it isn’t possible. As the commenters point out, LINQ is for querying collections of things. You don’t appear to have a collection here: just an if statement and an assignment.

    Furthermore, be careful about trying to convert things to LINQ unnecessarily. As you start to understand LINQ better, you’ll find yourself naturally using it for a variety of purposes. But starting off with the assumption that code will be better with LINQ is probably a fallacy.

    Edit

    As mentioned earlier, LINQ is about querying a collection for a set of results. If you only want one result, you can use Single, First, SingleOrDefault, or FirstOrDefault to get it out of the resulting collection.

     var gradeValues = from DataRow gradeRow in GraceTable.Rows
                                 let marksAbove = gradeRow.Field<decimal>("EXG_MARKS_ABOVE") 
                                 let marksBelow = gradeRow.Field<decimal>("EXG_MARKS_BELOW")
                                 where obtMarksRow.Field<decimal>("Percentage") >= marksAbove && obtMarksRow.Field<decimal>("Percentage") <= marksBelow
                                 select gradeRow.Field<string>("EXG_GRADE_NAME");
    
    var firstGradeValue = gradeValues.First(); // will throw exception if there were no matches.
    Console.WriteLine(firstGradeValue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if it's a silly question , but I'm just starting learning GWT and
Sorry if this seems like a dumb question but I am just learning bash
Sorry, I'm just playing around with mysql and learning as I go along. Here's
Sorry for the noobish question here, but I am just learning C++ and I
Sorry if this is a noob questions. I just started learning WPF so hopefully
Sorry I'm still a noob and just learning to program as I go and
I just started learning C#. Sorry for the noob question. My first training app
I'm just learning Haskell, so sorry if my question is stupid. I'm reading learnyouahaskell.com
Sorry if this is really basic but I am just learning PHP. I have
I just started learning XSLT,now I am following some on-line tutorial of it,and I

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.