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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:03:37+00:00 2026-06-11T21:03:37+00:00

This is a noob question, I apologize. I have been trying for a while

  • 0

This is a noob question, I apologize. I have been trying for a while to figure out how to add an object to this array. I have an Employee class, and a Salary class that inherits from Emp, and an Hourly class that does. I created an array like this,

        public Employee[] _Employees;
        ...    
        Employee[] _Employees = new Employee[]{ 
        new Hourly("1000", "Harry","Potter", "L.", "Privet Drive", "201-9090", "40.00", "12.00"),
        new Salary("2201", "A.", "A.", "Dumbledore", "Hogewarts", "803-1230", "1200"),
        new Hourly("3330", "R.","Weasley", "R.", "The Burrow", "892-2000", "40", "10.00"),
        new Salary("4040", "R.", "R.", "Hagrid", "Hogwarts", "910-8765", "1000")
                                                    };

And now I want to add objects to the array that I have read in from a text file. I am doing it like this right now;

                      if(rstring == "H")
                {
                    string fullName = data.ReadLine();
                    string empNum = data.ReadLine();
                    string address = data.ReadLine();
                    string phoneNum = data.ReadLine();
                    string hrWorked = data.ReadLine();
                    string hrRate = data.ReadLine();

                    string[] splitName = fullName.Split(new Char[] { ' ' });

                    string fName = splitName[0];
                    string mName = splitName[1];
                    string lName = splitName[2];

                     _MyForm._Employees = new Employee[] {new Hourly ( empNum, fName, mName, lName, address, phoneNum, hrWorked, hrRate ) };

which doesn’t give me any error, but when I look at what is stored in the _Employees class, it just has the info from above and nothing else. Let me know if I need to explain myself better. Just let me know if I need to go about it another way, or what I need to do to add the read info to this _Employees 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-06-11T21:03:38+00:00Added an answer on June 11, 2026 at 9:03 pm

    Instead of having an array, you should consider using a List<Employee>. This will let you add any number of elements to the list, without recreating it yourself:

    private List<Employee> employees = new List<Employee>();
    public IList<Employee> Employees { get { return this.employees; } }
    
    // ...
    this.employees.Add(new Hourly("1000", "Harry","Potter", "L.", "Privet Drive", "201-9090", "40.00", "12.00"));
    // .. Add all
    

    Then, when you want to add a new one, you can use:

    _MyForm.Employees.Add(new Hourly ( empNum, fName, mName, lName, address, phoneNum, hrWorked, hrRate));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Noob question here! I have an array with hashes that looks like this: arr
I apologize if this is a noob question, but I can't seem to figure
This question may seem extremely noob-ish, I apologize. I've been periodically attempting for the
This is a noob question. If I have a ViewController and inside that class
This may sound like a noob question, because it is. I have tried for
Forgive the noob question, but I'm trying to get my head wrapped around this.
Hi Sorry for this noob question but here goes...i have a working slidetoggle on
This is a noob question: How do I add gems to my rails app
I know this question has been kind of asked and have looked into the
I'm new to c# so apologies if this is a noob question. I'm trying

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.