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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:03:51+00:00 2026-06-12T10:03:51+00:00

I have two private arrays in a class that runs a certain operation using

  • 0

I have two private arrays in a class that runs a certain operation using a method. After this method is called, those two arrays are filled with the results. It’s not a good practice to make those arrays properties, so I was planning to have a separate property that returns a clone of the private array.

1) What is the overhead of returning a clone of the array? Is it unnoticeable in every case?

2) I could use an indexer if there was just one array. Is there a specific mechanism to use indexers for more than one array in a 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-12T10:03:52+00:00Added an answer on June 12, 2026 at 10:03 am

    I think you mean “overhead” or “cost” and not “overload”. Anyway, computationally it’s O(1) so it depends on the size of tha rray, but generally speaking Array copying is a cheap operation if it’s under a thousand elements or so.

    If you don’t intend on the arrays to be modified then you could expose your private arrays by wrapping them in a ReadOnlyCollection<T> like so:

    private TWhatever[] _array;
    public ReadOnlyCollection<TWhatever> Elements { get; private set; }
    
    public ClassConstructor() {
        _array = new TWhatever[1000];
        this.Elements = new ReadOnlyCollection<TWhatever>( _array );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two classes that look like this: public class ByteFilter {
I have a class that is a container for two fixed length arrays as
I have two different classes that have the same class as a private field.
I have two Doctrine entities that have a one-to-many relationship, like this: License class
I have a private inner class that encapsulates some functionality. It populates two ArrayLists.
Suppose we have two classes: class Base { private: int x; public: void f();
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
suppose you have two (or more) classes with private member vectors: class A {
I have two entities A and B. public class A{ @Id @GeneratedValue private Integer
I have two functions in an ActionScript class, they are: private function loaderCompleteHandler(event:Event):void {

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.