So, I've written a class, and one of the attributes of the class is an array of elements. For the sake of simplicity, say it's like this:
public class Arrays
{
private int[] myArray = new int[5];
}
Now, I know if I just make it public, I can access it like this:
Arrays a = new Arrays();
// do something to fill the array.
...
foreach (int i in a)
{
Console.WriteLine( "{0}", i);
}
But, the thing is, I want to keep the array private and use a public accessor to access the elements of the array. I know normally, were it not an array, you'd just use get and set accessor methods to return or set the values of the variable.
How would I create a public attribute in my class to access elements in an array? Later on, the elements might come from a database, or something, so I want to be able to use "true" data hiding and keep the actual array private.