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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:13:58+00:00 2026-05-27T05:13:58+00:00

I have a serializable dictionary that I created for a WCF REST web service

  • 0

I have a serializable dictionary that I created for a WCF REST web service

[Serializable]
public class jsonDictionary<TKey, TValue> : ISerializable
{
    private Dictionary<TKey, TValue> _Dictionary;
    public jsonDictionary()
    {
        _Dictionary = new Dictionary<TKey, TValue>();
    }
    public jsonDictionary(SerializationInfo info, StreamingContext context)
    {
        _Dictionary = new Dictionary<TKey, TValue>();
    }
    public TValue this[TKey key]
    {
        get { return _Dictionary[key]; }
        set { _Dictionary[key] = value; }
    }
    public void Add(TKey key, TValue value)
    {
        _Dictionary.Add(key, value);
    }
    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        foreach (TKey key in _Dictionary.Keys)
            info.AddValue(key.ToString(), _Dictionary[key]);
    }
}

I need to search through this dictionary to determine if 1 of several possible keys are present. I figured I would do this using a foreach statement kinda like so

foreach(var pair in dictionary)
{
    switch(pair.key)
    {
        case "something":

        Break;
        case "somethingelse":
        Break;
     }
}

However I keep getting the error:

    foreach statement cannot operate on variables of type 'ZTERest.jsonDictionary<string,string>' because 'ZTERest.jsonDictionary<string,string>' does not contain a public definition for 'GetEnumerator'

I know I have to do something with the IEnumerable or IEnumerator interface but I’m not sure how.

  • 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-27T05:13:58+00:00Added an answer on May 27, 2026 at 5:13 am

    A dictionary provides a key/value lookup for a reason, it’s not something that you usually iterate through. The generic Dictionary<> object that your class is wrapping already has a method called ContainsKey() that will do exactly what you’re looking for, without the overhead of going through every single key/value pair to see if it’s there. There’s no need to expose an iterator, just add this to your class.

    public bool ContainsKey(TKey key)
    {
        return _Dictionary.ContainsKey(key);
    }
    

    And call it like this.

    if (dictionary.ContainsKey("Something"))
    {
        //do something
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class: [Serializable] public class KVPair<TKey, TValue> { public TKey Key {
I have a class Image implementing ISerializable : [Serializable] [XmlRoot(ElementName = IMAGE)] [TypeConverter(typeof(ImageTypeConverter))] public
I have the following classes created: [Serializable] public class AppContext : IXmlSerializable { public
I need an XML-serializable dictionary. Actually, I now have two quite different programs that
I have a webservice [Serializable] public class DataObject { public int ID { get;
greetngs, i have two classes: [Serializable] public class FireGridUnit { public GridUnit FireGridLocation {
I have class: public class EnglishWord implements Serializable, Comparable, Cloneable { static Logger logger
I have a code like this: [Serializable] public class A { public int X
I have a class developed in F# that must be serializable. How can I
I have a RESTful service that I am developing in WCF . I am

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.