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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:31:40+00:00 2026-05-22T18:31:40+00:00

I have a class that has 3 public List’s in it. It’s basically just

  • 0

I have a class that has 3 public List’s in it. It’s basically just a data holding class.

I have a file with xml like delimiters(begging and ending tags of some sort, and data value that goes in between)

I have a parse class, that detects and adds certain things to certain lists from the data holding class. Basically I’m trying to detect an opening tag, store it in the opening tag List in my data holding class.

The way I’m trying to go (based on the teachers poor excuse for an example) is Main() instantiates the data holding class into an object, likewise for the parse class. Then it calls ParseMain to parse through the file and separate tags, data values, and closing tags to their respective List inside the data holding class. Then after the Parse class is finished, back in main, I’m calling up methods inside the data class to display the data.

I’m basically being yelled at by the compiler because, even though the xml data holder class has been instantiated in main, it doesn’t or can’t add to the public List’s I get specifically this error

“An object reference is required for the non-static field, method, or property”

How can I set the data reading classes List’s from my parse class?

My teacher gave a horrible example (he had everything but the classes marked static, and basically just slapped java/c++ style code into a couple classes)

This is all extra credit for a basic programming class I’m in.(the normal version is all structural inside one class)

***Edit- adding code snippets

                    XMLDoc XMLData = new XMLDoc();
                    XMLParse parseXML1 = new XMLParse();


                    //Calls the parseXML1 method passing it
                    //the name of the currently opened file.
                    parseXML1.MainParse(fileIn);

then to my main parse

    public void MainParse(FileStream fileIn)
    {

        int byteIn;


        while ((byteIn = fileIn.ReadByte()) != -1)
        {

            if (byteIn == '<')
            {
                ParseElement(ref byteIn,fileIn);
            }

ParseElement looks like

    public void ParseElement(ref int byteIn,FileStream fileIn)
    {
        token += byteIn;
        //First I need to get the entire tag stored in token
        do
        {        
            byteIn = fileIn.ReadByte();
            token += byteIn;
        } while (byteIn != '>');
        token += '>';

        //now I insert a / into my compare token
        compareToken = token;
        compareToken.Insert(1,"/");

        //It's an ending tag
        if (token == compareToken)
        {
            //figure this out later
        }
        //It's an opening tag,store it into element list
        else
        {
            XMLDoc.elements.Add(token);
            //also tried XMLData/elements/Add(token)
        }

    }

and finally my XMLDoc class looks like….

class XMLDoc
{
    public List<string> elements;
    public List<string> dataValues;
    public List<string> endingElements;

    public XMLDoc()
    {
        elements = new List<string>();
        dataValues = new List<string>();
        endingElements = new List<string>();
    }

    //This method simply displays the contents of the arrays
    public void DisplayCollected()
    {
        Console.WriteLine("Begin unformatted dump");
        for (int ii = 0; ii <= elements.Count;ii++)
        {
            Console.WriteLine("\n"+elements[ii]+dataValues[ii]+
                "\n"+endingElements[ii]);
        }
        Console.WriteLine("End unformatted dump\n");
    }

    //This method will generate an xml style display
    //To add later

}

I’m playing around,learning by doing and such. I’ve at this point had to abandon the teachers example, as mentioned above he just made every method in every class static, probably because he slapped his example together from the main lab work(which is structural and all inside the first class)

  • 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-22T18:31:41+00:00Added an answer on May 22, 2026 at 6:31 pm

    EDIT: Okay, it looks like you just need to pass the reference to the object around, e.g.

    XmlDoc xmlData = new XmlDoc();
    XmlParser parser = new XmlParser();
    parser.MainParse(xmlData, fileIn)
    
    ...
    
    public void MainParse(XmlDoc xmlData, FileStream fileIn)
    {
        ...
        ParseElement(xmlData, ref byteIn, fileIn);
        ...
    }
    
    public void ParseElement(XmlDoc xmlData, ref int byteIn,FileStream fileIn)
    {
        ...
    }
    

    I’ve adjusted the names slightly to be more sensible IMO.

    I would recommend that you don’t use public fields in XmlDoc, by the way. Public fields violate encapsulation – use properties if you really need to just expose values, but ideally put more behaviour in the object itself.

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

Sidebar

Related Questions

I have a Question class that has public List property that can contain several
I have a class that has an internal list of other objects like so:
Let's say I have a class that has a member called data which is
I have a page base class that has no .aspx file and so I
I have an Order class that has a list of OrderTransactions and I mapped
I have a class named WhatClass that has List field in it. I need
I have a class that has a Generic type G In my class model
I have a class that has some properties. And I want something that calculates
I have a class that has a vector of another class objects as a
I have a base class that has a private static member: class Base {

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.