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

  • Home
  • SEARCH
  • 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 7702767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:18:11+00:00 2026-05-31T23:18:11+00:00

I am trying to create an struct-array. I used the example provided by @JonSkeet

  • 0

I am trying to create an struct-array. I used the example provided by @JonSkeet found in this SO post to create the example below:

 public class JonSkeetClass
    {

        public struct ReportDetails
        {
           private readonly int indexd;
           private readonly string name;

            public ReportDetails(int indexd, string name)
            {
                this.indexd = indexd;
                this.name = name;
            }

            public int Indexd { get { return indexd; } }
            public string Name { get { return name; } }
        }


        static readonly IList<ReportDetails> MyArray = new ReadOnlyCollection<ReportDetails>
        (
        new[]
        {

            new ReportDetails(0, "Daily Unload Counts by Group"),
                    new ReportDetails(1,"Daily Unloads")        

        });


      public statis IList<ReportDetails> GetMyArray
      {
        get{ return MyArray;  }
       }


    }

I am now unsure how to use this class in my code as the MyArray IList is not exposing any methods or properties.

Update1: Code sample above has been updated with the suggestion from @Adrian.

To initialize:

IList<JonSkeetClass.ReportDetails> MyArray = JonSkeetClass.GetMyArray;
MessageBox.Show( MyArray[0].Name.ToString());
  • 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-31T23:18:12+00:00Added an answer on May 31, 2026 at 11:18 pm

    You need to expose it via a public method

    /*public*/ class JonSkeetClass  /*the visibility of this class depends on where you'll be using it*/
        {
             public struct ReportDetails /*this needs to be public also (or internal)*/
             {
                 ....
             }
             public static  IList<ReportDetails> GetMyArray
             {
                 get
                 {
                    return MyArray;
                 }
             }
    
        }
    

    edit

    You can’t access MyArray field outside the class because is a private member. This means you need to add a public property which exposes this field.

    To access MyArray[0].Name, call

    JonSkeetClass.GetMyArray[0].Name
    

    edit 2

    Actually you don’t need an extra property, since the collection is readonly, also the items, make that field public, that’s it

    public static readonly IList<ReportDetails> MyArray ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a class that can manage bidimensional array. I used the
I was trying to create a pseudo super struct to print array of structs.
I'm trying to create an array of a struct, which I have done and
I'm trying to create an array of structs. Is the code below valid? I
I am trying to create a base class that is a wrapper around std::array
I'm trying to create an array of structs and also a pointer to that
Im trying to create an array of tm* structs, and then return them at
I'm trying to create a function to create a new basewith another struct as
I'm trying to create a structure array which links input strings to classes as
I have been trying to create a 2D array of vector for a game.

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.