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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:25:33+00:00 2026-05-22T19:25:33+00:00

1) I’m still quite new to programming and have read a bit about getters

  • 0

1) I’m still quite new to programming and have read a bit about getters and setters. But I really don’t understand why they are used.. Could anyone explain it, or point me to an article? (The ones I read were not really understandable for me…)

2) In my current project I have a class where I declare and initialize an array of structs. I now need to access the array from another class, but it gives me the error: An object reference is required to access non-static member 'BaseCharacter.Attributes'.

I figures this could mean I need to use getters and setters? But how does this work for arrays?

Thanks in advance!

Simon.

EDIT: 2nd question got solved, which brings me to something else. When I want to use some class in another one, I’m making a new instance of the class, right? And this means I get the original values?
But that’s not what I want.

The second class is used to generate the UI, and needs the values I’m keeping in the first class.

At some point I will implement save files (XML or even on a server in later stage). Can I then just get the values from those files?

  • 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-22T19:25:34+00:00Added an answer on May 22, 2026 at 7:25 pm

    For the getters and setters (the things that use them are called Properties) it’s just a convenient and nice-looking way to make people think they’re using a variable, but to do some computation whenever the variable is updated or accessed. For instance:

    BankAccount.Interest
    

    looks better than

    BankAccount.GetInterest()
    

    Even though you can calculate the interest at the time it is requested in both cases.

    They are also used to make a variable be able to be accessed from outside the class, but changeable only from within the class with this technique:

    public double Interest {
        get;
        private set;
    }
    

    For an example of a setter being used, if you’ve ever used Windows Forms and updated a control’s Height or Width property, you’re using a setter. While it looks like you’re using a normal instance variable like c.Height = 400, you’re really letting c update it’s position by redrawing at a new place. So setters notify you exactly when a variable is changed, so your class can update other things base on the new value.

    Yet another application of Properties is that you can check the value people try to set the property to. For instance, if you want to maintain an interest rate for each bank account but you don’t want to allow negative numbers or numbers over 50, you just use a setter:

    private int _interestRate = someDefault;
    public int InterestRate {
        get { return _interestRate; }
        set {
            if (value < 0 || value > 50)
                throw new SomeException(); // or just don't update _interestRate
            _interestRate = value;
        }
    }
    

    This way people can’t set public values to invalid values.


    For your second question, you can do one of two things depending on what you’re trying to do.

    One: You can make that member static. That means that just one of them exists for the entire class instead of one per instance of the class. Then you can access it by ClassName.MemberName.

    You can do that this way:

    // inside the BaseCharacter class definition:
    public static SomeStruct[] Attributes = new SomeStruct[size];
    
    // then to use it somewhere else in your code, do something with
    BaseCharacter.Attributes[index]
    

    Two: You have to make an instance of the class and access the array through that. This means that each object will have its own seperate array.

    You’d do that like this:

    BaseCharacter bc = new BaseCharacter();
    // use bc.Attributes
    

    The second one is probably what you’ll want to do, since you probably will want to modify each character’s attributes seperately from all the other characters.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.