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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:58:04+00:00 2026-06-10T00:58:04+00:00

I wrote a short static method inside my class to iterate over some Hashtable

  • 0

I wrote a short static method inside my class to iterate over some Hashtables I have in order of the keys (strings) but I’m getting a weird compiler error. Here’s the method in question:

public static DictionaryEntry inorderHashtable(Hashtable ht) {
    string[] keys = ht.Keys.Cast<string>().ToArray<string>();
    Array.Sort(keys);

    foreach (string key in keys) {
        yield return new DictionaryEntry(key, ht[key]);
    }
}

This is later used inside the class like this:

foreach(DictionaryEntry dentry in inorderHashtable(myTable)) { /* ... */ }

Here’s the error I’m getting from VS2008: 'ns.myclass.inorderHashtable(System.Collections.Hashtable)' cannot be an iterator block because 'System.Collections.DictionaryEntry' is not an iterator interface type

What’s a way around this error? Thanks in advance.

  • 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-10T00:58:05+00:00Added an answer on June 10, 2026 at 12:58 am

    Your method needs to have the return type IEnumerable<DictionaryEntry>.

    Basically, by using yield return instead of return, you’re not returning one DictionaryEntry, you’re (potentially) returning many.

    See here and here if you’re unsure what’s going on.

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

Sidebar

Related Questions

I have a short question i have wrote this in java. Old code: class
I wrote a class MyListView in order to add an method to set sort
I have this array of strings private static String[] colorsArray = { #bde876, #ff8581,
I have an extension method with the following signature: public static Expression<Func<T, bool>> And<T>(this
I'm creating a class to manage text files. I have a method to write
I wrote a class method using STL find_if . The code is the following:
I have a static function in a class with two overloads. Both the overloads
I wrote a custom table model for a JTable: class MessageTableModel{ private static Set<Message>
I wrote this short program which has a tiny GUI. Its supposed to allow
I wrote a short bit of code to simply skip num_lines lines in an

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.