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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:34:04+00:00 2026-06-04T13:34:04+00:00

Hi the intent of the code below is to return a static class which

  • 0

Hi the intent of the code below is to return a static class which holds a related set of data. Can you recommend how I can do this better?

public class People
{
    //want info to be setup in this class, so it can be accessed elsewhere
    public static readonly string[] ab = { "ALBERT", "EINSTEIN"};       
    public static readonly string[] dk = { "DONALD", "KNUTH" };

   //is this efficient or instantiated once per access? IF SO HOW CAN I DO THIS BETTER? 
    public static readonly Info AB = new Info(ab, 100); 
    public static readonly Info DK = new Info(dk, 80);

}

public class Info
{
    private string[] _name;
    private int _age;

    public string[] Name { get{ return _name}; }
    public int Age { get { return _age; } }

    public Info(string[] n, int a)
    {
        _name = n;
        _age = a;
    }
}
  • 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-04T13:34:06+00:00Added an answer on June 4, 2026 at 1:34 pm

    is this efficient or instantiated once per access?

    If you mean the moment at when the instances of Info are constructed, they are built before the first access to the member. So no matters how many times you call People.AB, the object will be the same.

    From MSDN about Static Classes and Static Class Members:

    Static members are initialized before the static member is accessed for the first time and before the static constructor, if there is one, is called.

    If you want to make your instances of Info totally immutable (as Daniel says, the values of _name could be changed once you get a reference to the array), you can change the type of _name and its property accesor to:

    private List<string> _name;
    
    public IList<string> Name { get { return _name.AsReadOnly(); } }
    

    Hope I’ve understood your needs!

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

Sidebar

Related Questions

I want to send data through URL.I've tried the below code: Intent browserIntent =
i have this IntentService code which run a service once: protected void onHandleIntent(Intent intent)
Here is my intent-filter code... <activity android:name=IntentReceiver> <intent-filter> <action android:name=android.nfc.action.TAG_DISCOVERED/> <category android:name=android.intent.category.DEFAULT /> <data
I want to send an SMS via intent, but when I use this code,
I have this code: package com.powergroupbd.timer; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer;
In the code below, I am reacting to an activity return. When I get
I'm writing a project to read pdf files. My main class uses this code
In the code below, my intent is to call one of two overloaded constructors
as you can see from the code below im just trying to get the
i am checking networking connection using the below code: public static boolean haveInternet(Context ctx)

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.