djm-web

How do I do this in C#

I have an ArrayList and the following code :

levelObject objtest;

objtest = (levelObject)levelObjectList[10];

objtest.matWorld = Matrix.Identity;

I want the matWorld of the 10th element of the arraylist to change to identity when I change the objtest.matWorld.

I thought objects were references and not value types.



Re: XNA Game Studio Express C# Brainwrong

dokks

Well, given the code above, you would be operating on the 11th item in the arraylist, as arraylists are 0 based. Other than that, without seeing the rest of your code, It's impossible to know what you're trying to do.





Re: XNA Game Studio Express C# Brainwrong

djm-web

Yes, that would be the 11th item, my bad :)

I'm just trying to store a reference to a single item in an arraylist and then change that items values via the reference ie similar to a pointer to an array element in C.





Re: XNA Game Studio Express C# Brainwrong

djm-web

Maybe it's because my levelObject type is a struct

public struct levelObject

{

public Matrix matWorld;

public BoundingSphere sphereWorld;

}





Re: XNA Game Studio Express C# Brainwrong

dokks

Yep, that's why, change it to a class and it should work fine.



Re: XNA Game Studio Express C# Brainwrong

Fluxtah

Don't mean to be picky but you should really use pascal case for your class names, LevelObject would be more appropriate.

Sorry, had to mention it ;)





Re: XNA Game Studio Express C# Brainwrong

dokks

I didn't even notice that ha. My biggest pet peeve is the dreaded, make me hold down shift and blow my intellisence to bits m_ and _property grrr