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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:49:52+00:00 2026-05-12T20:49:52+00:00

Forgive me if this is a duplicate, but it’s a minor issue for me

  • 0

Forgive me if this is a duplicate, but it’s a minor issue for me and I can only spend so long on my curiosity. Why is it that when I use an implicitly typed loop variable in a foreach block, I get no Intellisense? The inferred type seems to be quite obvious.

I am using ReSharper, but when I switch the Intellisense to VS I get the same behaviour, and this don’t think it’s to blame.

EDIT: Sorry, a bit later, but I was iterating DataTable.Rows, which uses an untyped ieterator, as Marc explains below.

  • 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-12T20:49:52+00:00Added an answer on May 12, 2026 at 8:49 pm

    I suspect that the data you are enumerating is not typed – for example, a lot of things that were written in 1.1 only implement IEnumerable, and don’t have a custom iterator (you don’t actually need IEnumerable<T> to do typed iteration – and indeed you don’t even need IEnumerable to use foreach; a lot of 1.1 typed wrote special enumerator types to avoid boxing/casting etc – lots of work). In many cases it would be a breaking change to fix them.

    A trivial example here is PropertyDescriptorCollection:

    var props = TypeDescriptor.GetProperties(obj);
    foreach(PropertyDescriptor prop in props) {...} // fine
    

    but actually, PropertDescriptorCollection‘s enumerator is just IEnumerator, so Current is object – and hence you’ll always get object when you use var:

    var props = TypeDescriptor.GetProperties(obj);
    foreach(var prop in props) {...} // prop is "object"
    

    Contrast this to the (equally 1.1) StringCollection; this has a custom enumerator (StringEnumerator); so if you used foreach with var, you’d get string (not object).

    In anything 2.0 and above, it would be reasonable to expect better typing, for two reasons:

    • generics (for the simple cases), making it possible to write strongly-typed collections sensibly
    • iterator blocks (for the non-trivial cases), making it possible to write custom iterators without going insane

    But even then there are still cases when you don’t get the type you expect; you can either (and perhaps more clearly) specify the type manually, or use Cast<T>() / OfType<T>().

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

Sidebar

Related Questions

Duplicate Should C# methods that can be static be static? Please forgive me if
Forgive me if this is a simple problem but I can't seem to find
Please forgive my long question. I have an idea for a design that I
(THIS IS A DUPLICATE, I FORGOT A TAG, PLEASE FORGIVE) I'm writing a small
Forgive me if this is in the wrong place, but I figured a few
Forgive me If this is a dumb question. Can one programmatically observe the contents
I never studied OSes, so forgive me if this sounds basic or silly, but
Forgive me if this is a simple question, but is a UISwitch a boolean
Forgive me if this might be a dumb question but, I'm in an assembly
Forgive me if this is a newbie question, but... When playing video, is it

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.