J
J. Marcelo Barbieri
I managed to do a foreach to go through all the elements in class2 using a
public property, as you can find bellow.
I know I could obtain the same result implementing the IEnumerable
interface, but what would be the difference???
thanks,
namespace IndexerTest
{
class Class1
{
static void Main(string[] args)
{
int len = 2;
Class2 c2 = new Class2(len);
c2[0] = "First String";
c2[1] = "Second String";
foreach(string s in c2)...
}
}
public class Class2
{
public Class2(){}
public Class2(int i)
{
sa = new string;
}
private string[] sa;
public string this[int i]
{
get{return sa;}
set{sa = value;}
}
public string[]saProperty
{ get{return string[]sa;} }
}
}
public property, as you can find bellow.
I know I could obtain the same result implementing the IEnumerable
interface, but what would be the difference???
thanks,
namespace IndexerTest
{
class Class1
{
static void Main(string[] args)
{
int len = 2;
Class2 c2 = new Class2(len);
c2[0] = "First String";
c2[1] = "Second String";
foreach(string s in c2)...
}
}
public class Class2
{
public Class2(){}
public Class2(int i)
{
sa = new string;
}
private string[] sa;
public string this[int i]
{
get{return sa;}
set{sa = value;}
}
public string[]saProperty
{ get{return string[]sa;} }
}
}