Hello and thank you for your help in advance!
I develop a program in C# and reached a point where I really need to use
pointers. I do not
want to use them in an unsafe context though.
As with Java, I know that I can use an unassigned variable as a pointer to
another object,
for example:
SomeClass someClass = new SomeClass();
SomeClass refClass = null;
refClass = someClass;
Recently I spoke with an experienced programmer and he told me that you do
not want to use
this kind of pointers in C# or Java. Unfortunately, I forgot to ask him
about the reason why I
would not want to use pointers like this.
So my question is:
Why shouldn't I use a pointer like this? Especially why would I want to
refrain from creating
an array list using the technique shown above?
I need quick access to an array list where the elements are sorted by more
than 1 criteria.
To give more details, I want to use it in code like this:
class MyClass
{
int X;
int Y;
int Z;
MyClass nextX, nextY, nextZ;
}
ContainerStruct
....and then use some code like this (when there are already some MyClass
instances):
MyClass searchClass = headClass.nextX; // I define the headClass as the
first element of the list here
int x = 3; // any value
while( searchClass.X > x )
{
searchClass = searchClass.nextX;
}
Are there any more elegant ways to do this?
Thank you!
I develop a program in C# and reached a point where I really need to use
pointers. I do not
want to use them in an unsafe context though.
As with Java, I know that I can use an unassigned variable as a pointer to
another object,
for example:
SomeClass someClass = new SomeClass();
SomeClass refClass = null;
refClass = someClass;
Recently I spoke with an experienced programmer and he told me that you do
not want to use
this kind of pointers in C# or Java. Unfortunately, I forgot to ask him
about the reason why I
would not want to use pointers like this.
So my question is:
Why shouldn't I use a pointer like this? Especially why would I want to
refrain from creating
an array list using the technique shown above?
I need quick access to an array list where the elements are sorted by more
than 1 criteria.
To give more details, I want to use it in code like this:
class MyClass
{
int X;
int Y;
int Z;
MyClass nextX, nextY, nextZ;
}
ContainerStruct
....and then use some code like this (when there are already some MyClass
instances):
MyClass searchClass = headClass.nextX; // I define the headClass as the
first element of the list here
int x = 3; // any value
while( searchClass.X > x )
{
searchClass = searchClass.nextX;
}
Are there any more elegant ways to do this?
Thank you!