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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:09:37+00:00 2026-06-14T08:09:37+00:00

How to minimize the overhead by implementing an Array Wrapper? 1 Which Interface/Type to

  • 0

How to minimize the overhead by implementing an Array Wrapper?

1 Which Interface/Type to choose for MyProviderInfos?

2 Is that reasonable to use private static enumerator? NO, from the
answer

3 Should MyProviderInfos be a property and how to protect its members from modifications? internal/private SETTERS for members (from the same answer)

I tried going through SO articles about ICollection, Readonly-Collection, List, IList, Array, but still confused what would be best for the scenario:

  • The Array MyProviderInfos is formed by the compile time and will not (must not) be changed at the run-time.
  • The Class is (must be) Enumerable (with Elements of the Array MyProviderInfos) and Custom List functions (.Add .Remove) are NOT necessary.
  • The class HAS static functions, which use the Array.
  • The class MUST be non-static to support Indexing.

Code:

 public class MyIdentifiers : IEnumerable<MyProviderInfo>
 {
   //public static IList<MyProviderInfo> getMyProviderInfos() 
   //{ return MyProviderInfos; }

    public static int MyProviderCount()
    {
        return MyProviderInfos.Count;
    }

    public static readonly IList<MyProviderInfo> MyProviderInfos = new[]
    {
        new MyProviderInfo
            {
                MyProvider = MyProvider.FirstProvider,
                Url = "https://www.google.com",                       
            }
    };

    private static IEnumerator<MyProviderInfo> _enumerator = 
((IEnumerable<MyProviderInfo>)MyProviderInfos).GetEnumerator();

    public IEnumerator<MyProviderInfo> GetEnumerator()
    {
        return _enumerator;
        //return ((IEnumerable<MyProviderInfo>)MyProviderInfos).GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }

}
  • 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-14T08:09:38+00:00Added an answer on June 14, 2026 at 8:09 am

    Which Interface/Type to choose for MyProviderInfos?

    Unless you want to limit features directly visible to your users you should always return the less generic type (in your case the array itself).

    As general rule it’s a good practice to accept the most generic possible type as parameter (for example if you just want to enumerate a collection then declare that parameter as IEnumerable<T>) and the less generic as result (so users can use it as IEnumerable<T> if they just need that or as IList<T>, as needed, without fragile casts and conversions). Moreover, in your case, IList<T> supports adding items but this will throw at run-time because array is fixed size so you expose more than what they actually can do.

    For example:

    string[] ConvertToTitleCase(IEnumerable<string> names);
    

    Of course you can return an IEnumerable<string> too instead of string[], it may be appropriate if – for example – the implementation doesn’t create any array for the result to avoid an extra conversion.

    Is that reasonable to use private static enumerator?

    Absolutely no, an enumerator is an object with a state (take a look to any IEnumerator<T> implementation) then it can’t be static (imagine when called by different threads, for example).

    Should MyProviderInfos be a property and how to protect its members from modifications?

    It doesn’t need to be a property unless you want to provide some kind of lazy initialization. To protect its members the only thing you can do is to make them read-only (it doesn’t matter if the collection itself is read-only). How to do it depends on MyProviderInfo implementation. You may consider to do not expose any public setter for its properties. For example:

    class MyProviderInfo
    {
        public MyProviderInfo(Provider provider, string url)
        {
            Provider = provider;
            Url = url;
        }
    
        public Provider Provider
        {
            get;
            private set;
        }
    
        public string Url
        {
            get;
            private set;
        }
    }
    

    Or, without too many changes, keep your existing code but make setters internal (so users of your library won’t be able to modify them):

    class MyProviderInfo
    {
        public Provider Provider
        {
            get;
            internalset;
        }
    
        public string Url
        {
            get;
            internal set;
        }
    }
    

    To summarize a little bit I would rewrite that as this:

     public class MyIdentifiers : IEnumerable<MyProviderInfo>
     {
        public int Count
        {
            get { return _myProviderInfos.Count; }
        }
    
        public IEnumerator<MyProviderInfo> GetEnumerator()
        {
            return ((IEnumerable<MyProviderInfo>)_myProviderInfos ).GetEnumerator();
        }
    
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    
        private static readonly IList<MyProviderInfo> _myProviderInfos = new[]
        {
            new MyProviderInfo
                {
                    MyProvider = MyProvider.FirstProvider,
                    Url = "https://www.google.com",                       
                }
        };
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to minimize margins around a 1X2 figure, a figure which are
I read this article Optimize Parallel Downloads to Minimize Object Overhead and write a
I have a menu which looks like this: |Home|Options|Settings|Tools|Preferences|Edit| That's fine when a phone
Is that possible to minimize the UI at maximum in order to look like
I usually, almost without thinking anymore, use forward declarations so that I won't have
To minimize boilerplate code, I'd like to have a Socket and ServerSocket class which
I'm trying to minimize the number of vbs files that I have for a
How can i Minimize the window to the Taskbar? im using: FormBorderStyle = Windows.Forms.FormBorderStyle.None
Is it possible to minimize the default border of every side of a button?
When I minimize a window in qooxdoo, where does it go? Is there a

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.