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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:04:40+00:00 2026-06-10T20:04:40+00:00

I have a class with a private static List<String> collection. Now I want to

  • 0

I have a class with a private static List<String> collection. Now I want to return a readonly list. Would this be the ideal way of doing it? Would you do it another way? Is this the proper way?

namespace Test
{
    static class Storage
    {

        private static List<string> store;

        static Storage()
        {
            store = new List<string>();
        }

        //Is it okay to have a getter in my static class to return my List Collection
        public static System.Collections.ObjectModel.ReadOnlyCollection<string>getList
        {
            get
            {
                return stores.AsReadOnly();
            }
        }

        public static void addString(string add)
        {
            store.Add(add);
        }

    }
}
  • 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-10T20:04:42+00:00Added an answer on June 10, 2026 at 8:04 pm

    It depends on client expectations. If your clients expect that the contents of the list can change, then that’s (vaguely) okay. If they’re expecting an unchanging collection, then you’ll need to take a copy.

    Note that List<T> isn’t thread-safe to start with, which is a big red warning light when it comes to global mutable state, accessed with no obvious synchronization…

    (Having global mutable state is an issue to start with, IMO, affecting testability etc. Doing so in an unsafe way just makes it even worse.)

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

Sidebar

Related Questions

I've got a static class, called Test, and a private List collection. Now I
So I have created the following script: class spImageUpload() { private static System.Collections.Generic.List<string> keywords;
I have this class: public static class CsvWriter { private static StreamWriter _writer =
I have a class (singleton) and it contains a static Dictionary private static Dictionary<string,
I have simplified my code to this internal class Program { private static void
Let's say I have: public class Components<T> extends TupleList<Class<T>, String> { private static final
I have this small class looking like this: private static int field1 = -
I have a private static readonly field in my class: public class MyClass {
I have written this piece of code public class Test{ public static void main(String[]
I have a class class foo { public: foo(); foo( int ); private: static

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.