encapsulate array property in class

Posted on 2013-10-08
Medium Priority
Last Modified: 2014-02-11
I want a  c# class which has two private int[] arrays or Lists I dont mind which but I want a public property which allows me to get and set. I don't know in advance how many ints I will be saving.

Can't seem to figure it out, is it possible? please show an example

Question by:Paulmc999
LVL 45

Accepted Solution

AndyAinscow earned 1000 total points
ID: 39557933
something like this should get you started
public class x
  private List<int> listIntOne = new List<int>();
  public void AddToOne(int i) {listIntOne.Add(i)};
  public int GetFromOne(long indx) {return listIntOne[indx]; };
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 1000 total points
ID: 39558913
What is wrong with an automatic property?

public class IdContainer
    public List<int> IdList { get; private set; }

    public IdContainer()
        IdList = new List<int>();

Open in new window


Author Comment

ID: 39562114
Guys I'm sorry I haven't responded, was very busy with something else. I did try these before but didn't know if it was right thing but perhaps I was doing something wrong. Am going to try it today and get back to you.


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Native ability to set a user account password via AD GPO was removed because the passwords can be easily decrypted by any authenticated user in the domain. Microsoft recommends LAPS as a replacement and I have written an article that does something …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question