© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
5 replies
Pdawg

❔ How can I access a member of a different class in a dictionary

Hey! I'm trying to refactor my old JSON serializer code, but I ran into an issue. I can't access a string in another class named
RssTitle
RssTitle
. In this
Content
Content
property, there are 3 different strings that I need to access, RssTitle, RssDesc, and RssPubDate. When I use a dictionary like this:

 Resources = new List<WebTileResource>
                {
                    new WebTileResource
                    {
            Url = ResourceURL,
            Style = ResourceType,
            Content = new Dictionary<ContentList, string>
                        {
                            
                        }
                    }
                }
 Resources = new List<WebTileResource>
                {
                    new WebTileResource
                    {
            Url = ResourceURL,
            Style = ResourceType,
            Content = new Dictionary<ContentList, string>
                        {
                            
                        }
                    }
                }

It can't access those 3 strings, and just says that
RssTitle does not exist in the current context
RssTitle does not exist in the current context
. Here is the data model behind this code

public class WebTileResource
    {
        public string Url { get; set; }
        public string Style { get; set; }
        public Dictionary<ContentList, string> Content { get; set; }
    }

    public class ContentList
    {
        public string RssTitle { get; set; }
        public string RssDesc { get; set; }
        public string RssPubDate { get; set; }
    }
public class WebTileResource
    {
        public string Url { get; set; }
        public string Style { get; set; }
        public Dictionary<ContentList, string> Content { get; set; }
    }

    public class ContentList
    {
        public string RssTitle { get; set; }
        public string RssDesc { get; set; }
        public string RssPubDate { get; set; }
    }

If I use a
List
List
, like this:
public List<ContentList> Content { get; set; }
public List<ContentList> Content { get; set; }
, it creates an array in the serialized JSON. I need it to not be an array. Here's what the final JSON looks like:

"resources": [
{
"url": "some_rss_feed",
"style": "Simple",
"content": [{
"rssTitle": "Add any variables that you need here",
"rssDesc": "Add any variables that you need here",
"rssPubDate": "You can pull any of the data attributes from a selected data source!"
      }]
    }
  ],
"resources": [
{
"url": "some_rss_feed",
"style": "Simple",
"content": [{
"rssTitle": "Add any variables that you need here",
"rssDesc": "Add any variables that you need here",
"rssPubDate": "You can pull any of the data attributes from a selected data source!"
      }]
    }
  ],

I need it to look like this:
"resources": [
{
"url": "some_rss_feed",
"style": "Simple",
"content": {
"rssTitle": "Add any variables that you need here",
"rssDesc": "Add any variables that you need here",
"rssPubDate": "You can pull any of the data attributes from a selected data source!"
      }
    }
  ],
"resources": [
{
"url": "some_rss_feed",
"style": "Simple",
"content": {
"rssTitle": "Add any variables that you need here",
"rssDesc": "Add any variables that you need here",
"rssPubDate": "You can pull any of the data attributes from a selected data source!"
      }
    }
  ],
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ How to access a button from a different class?
C#CC# / help
3y ago
❔ How can I access items from another form in a different form?
C#CC# / help
3y ago
✅ Declaring a Dictionary as a Member Variable
C#CC# / help
3y ago
creating objects in a different class
C#CC# / help
3y ago