M
Matthias S.
Hi,
I'm trying to provide the user of my class access to the objects in a
collection without allowing him to modify (add/remove/clear items) the
collection. I thought I can do it by providing a IEnumerator. But this
thingy can't be used directly, as shown in the code below. How can this
be done?
Thanks in advance.
Matthias
Here the test I tried:
using System;
using System.Collections;
using System.Collections;
public class MyClass
{
public static void Main()
{
string s1 = "Hello";
string s2 = "World!";
a.Add(s1);
a.Add(s2);
foreach (String s in GetEnumerator())
Console.WriteLine(s);
}
private static IEnumerator GetEnumerator() {
return a.GetEnumerator();
}
private static ArrayList a = new ArrayList();
}
I'm trying to provide the user of my class access to the objects in a
collection without allowing him to modify (add/remove/clear items) the
collection. I thought I can do it by providing a IEnumerator. But this
thingy can't be used directly, as shown in the code below. How can this
be done?
Thanks in advance.
Matthias
Here the test I tried:
using System;
using System.Collections;
using System.Collections;
public class MyClass
{
public static void Main()
{
string s1 = "Hello";
string s2 = "World!";
a.Add(s1);
a.Add(s2);
foreach (String s in GetEnumerator())
Console.WriteLine(s);
}
private static IEnumerator GetEnumerator() {
return a.GetEnumerator();
}
private static ArrayList a = new ArrayList();
}