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 7498729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:34:27+00:00 2026-05-29T19:34:27+00:00

I am new to generics in C# and while reading a book stumbled upon

  • 0

I am new to generics in C# and while reading a book stumbled upon an example:

var cars = from car in data.AsEnumerable()
  where
    car.Field<string>("Color") == "Red"
    select new
    {
      ID = car.Field<int>("CarID"),
      Make = car.Field<string>("Make")
    };

The author says that car.Field<string>("Color") gives the additional compile-time checking comparing to (string)car["Color"]. But how does the compiler know that car.Field<string>("Color") is compilable for “Color” and not for “CarID”? Or there is some kind of another “additional compile-time checking” that I miss?

  • 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-29T19:34:29+00:00Added an answer on May 29, 2026 at 7:34 pm

    It doesn’t give you any additional compile-time checking. If you use the wrong type, in both cases you’ll get an exception during run-time.

    But it can be useful to do additional stuff that simple cast can’t. For example Field<int>("CarId") could call a method that converts the string in the field to an int.

    And assuming you’re talking about DataRow.Field<T>(), then, according to the documentation, it’s useful mostly for dealing with null values and nullable types correctly.

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

Sidebar

Related Questions

I mostly use Java and generics are relatively new. I keep reading that Java
I'm fairly new (ok, REALLy new) to generics but I love the idea of
This question came to my mind while I am reading the post Why doesn't
I'm relatively new to Java and am used to generics in C# so have
i want to fill the data of the charts from values i have in
The Following code is used as an example as an into to Generics. //
Good day. When i try to run the example from MSDN. But it failed
I am new to this whole design concept, and in reading for the last
I Know I can use Generics while defining the ArrayList to do that. But
I have run into an odd casting issue while using generics. The following code

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.