We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


how do you right the 'get' and 'set' accessors for an array property

Medium Priority
Last Modified: 2012-05-05
So I'm trying to use a instance variable that is an array. I want to write a property that will access this private instance variable. I can't find the syntax to do this.
Watch Question

Senior Software Engineer
Hi, syntax is:

      public class MyClass {
            //Instance array variable
            private string[] dataArray;

            public string[] Data {
                  get {
                        return this.dataArray;
                  set {
                        this.dataArray = value;

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Ravi SinghSenior Software Engineer

If your defining a collection class then you could also make use of an indexer, which would allow users of your class to use the [] operator on a reference (just like using a standard array):


MyClass myClass = new MyClass();
string someData = myClass[0];

See: http://www.developer.com/net/csharp/article.php/1547581

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.