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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:33:04+00:00 2026-05-11T01:33:04+00:00

C# 3.0 introduced the var keyword. And when compiled, the compiler will insert the

  • 0

C# 3.0 introduced the var keyword. And when compiled, the compiler will insert the right types for you. This means that it will even work on a 2.0 runtime. So far so good. But the other day I found a case where, the var keyword would be replaced with just object and thus not specific enough. Say you have something like:

var data = AdoMD.GetData(...); // GetData returns a DataTable  foreach (var row in data.Rows) {      string blah = (string)row[0]; // it fails since it's of type object } 

When I try to use row both IntelliSense and the compiler tells me that it is of type object. data.Rows is of type System.Data.DataRowCollection. The following works:

var data = AdoMD.GetData(...); // GetData returns a DataTable  foreach (DataRow row in data.Rows) {      string blah = (string)row[0]; // works since it now has the right type } 

This is not a question about the usage of var, there is a thread for that here.

I’m using Visual Studio 2008 SP1 btw.

Edit: correct code now attached.

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

    I think I see the problem. DataRowCollection is non-generic and thus the only thing the compiler knows is that contains objects of type Object. If it had been a generic datastructure this would have worked.

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

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer A tricky question, but finally got this figured out. The… May 11, 2026 at 10:57 am
  • added an answer I don't think the coerce callback is meant to be… May 11, 2026 at 10:57 am
  • added an answer Keep in mind that ASP.NET AJAX is comprised of both… May 11, 2026 at 10:57 am

Related Questions

C# 3.0 introduced the var keyword. And when compiled, the compiler will insert the
C# 3.0 Extension methods add extensions to the base Type making calling that method
In c# (3.0 or 3.5, so we can use lambdas), is there an elegant
With C# 3.0 you could use many of its features (object initializers, var variables,
The C# 3.0 spec has the following code example in section 10.6.1.3 Output parameters:
On C# 3.0 and .NET 3.5, imagine there's an interface: public interface INameable {
In C# 3.0, I have a property which is suppose to contain the version
With C# 3.0, I know you can extend methods using the 'this' nomenclature. I'm
I am using C# 3.0 / .NET 3.5 and planning to build an eCommerce
Is there any way to create C# 3.0 anonymous object via Reflection at runtime

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.