A
A Ratcliffe
Here's where I show my C++ roots, and the fact that I am still learning C#,
but...
In C++, if I had a small array in a class, I would simply define it in the
class to the correct dimensions. If I wished to access the array via
operator, I would overload the [] operator for the class. For example...
class cPoint3
{
private:
float _v[3];
public:
float& operator [](int i);
}
In C#, this all changes. On to my questions:-
A) In C#, as I understand it, I have to define the array as [], as in
private float [] _v;
and then set its size in the constructor, as
_v = new float[3]
Is this right? it seems a long winded way of setting something that I KNOW
is always going to be that size.
B)
How do I create the equivalent overloaded [] for the class in C#?
Sorry for bothering you all with such simplicity, but I was expecting
something closer to the C++ way of doing things, and it threw me into a spin
when VS.NET started highlighting everything as incorrect syntax.
Thanks in advance,
Yours,
Ann-Marie Ratcliffe
but...
In C++, if I had a small array in a class, I would simply define it in the
class to the correct dimensions. If I wished to access the array via
operator, I would overload the [] operator for the class. For example...
class cPoint3
{
private:
float _v[3];
public:
float& operator [](int i);
}
In C#, this all changes. On to my questions:-
A) In C#, as I understand it, I have to define the array as [], as in
private float [] _v;
and then set its size in the constructor, as
_v = new float[3]
Is this right? it seems a long winded way of setting something that I KNOW
is always going to be that size.
B)
How do I create the equivalent overloaded [] for the class in C#?
Sorry for bothering you all with such simplicity, but I was expecting
something closer to the C++ way of doing things, and it threw me into a spin
when VS.NET started highlighting everything as incorrect syntax.
Thanks in advance,
Yours,
Ann-Marie Ratcliffe