Any DefData in C#?

Miscellaneous Forums/General Discussion/Any DefData in C#?

Is there a defdata equivalent for c#?

Can someone point me to it. I'm looking at the c# docs now but am lost as what to look for.

Enums, maybe?

You could use a byte array to store the data and a Memorystream to pull it back again? Just a thought.

Hiya Amon, I dont think theres an equivalent DefData setup in C#. I'm assuming you want to fill an array with the data, which can be done like this:-

int [] intArray;
intArray = new int[3] {0, 1, 2};


So imagine that being a tilemap you want to initialize, you can do this:-

int [] intArray;
intArray = new int[77]  { 
 			1,1,1,1,1,1,1,1,1,1,1
			1,0,0,0,0,0,0,0,0,0,1
			1,0,0,0,0,0,0,0,0,0,1
			1,0,0,0,0,1,0,0,0,0,1
			1,0,0,0,0,0,0,0,0,0,1
			1,0,0,0,0,0,0,0,0,0,1
			1,1,1,1,1,1,1,1,1,1,1};


To add extra maps, just add more dimensions to the array and fill it up like so:-

int[,] multiArray = new int[3, 2] { {1, 2}, {3, 4}, {5, 6} };


Hope that helps

Ahh! Will try that, thanks fellas. :)

Always a pleasure me auld fruit! ;)

"To add extra maps, just add more dimensions to the array and fill it up like so:-"

Actually I would use an Arraylist for that filled with the original array. Arraylists are my new favorite thing.

Do not use arraylists. Use an array, or a generic list.

Heh... just mentioned this in your glowroids thread :)

Do not use arraylists

Why? speed?

1- If you put any valuetype's(int,float,char, basically any struct or enum ) into an array list, they have to be boxed( literally, wrapped in an object ), and then unboxed to be used.

2- You're forced to work with all items in the arraylist at the object level. I can't think of many real life scenarios where you won't need to cast them to more specific types. So you have the overhead of casting and the extra code you're required to write to do so( foreach, writes the code for you, but theres times when you may index into the collection, and you have to cast/check it ). With a generic list, no more cast. You can get to the members of said type, just like you were using an array.

3- ^Type Safety^ . You'll either be testing to make sure the items are what you expect or need them to be, or run the possibility of casting errors. With the generic list, the compiler won't let you do boneheaded things.

4- Generics can share code. Before .net 2.0, people used to write their own typesafe wrappers over arraylist. Codebloat is one result of that, because programs would be filled with a bunch of different versions of what was essentially the same thing. With generics, say you instantiate a List<Player> and a List<BadGuy>, and whatever other list(s). The runtime can share code between all of them.

For small programs, no one's going to notice any performance difference. But get too sloppy, and this stuff does add up.

The issue is, you gain absolutely nothing from using them. But you do lose on performance, and on the amount of typing your wrists have to do.

ArrayList has been written off in most developers minds. They were a stopgap measure while waiting for generics. There is no compelling reason to use them anymore.