Chaos Project

Game Development => Sea of Code => Topic started by: G_G on August 24, 2010, 11:32:48 am

Title: [RESOLVED][C#] Multi Variable Array/List?
Post by: G_G on August 24, 2010, 11:32:48 am
Basically what its like in Ruby. Ruby can have an array, and you can place anything in that array. Integers, strings, objects. Their not binded to just one type of array. So basically, I'm curious if its possible to create an array or list in c# that can hold multiple object types.
Title: Re: [C#] Multi Variable Array/List?
Post by: stripe103 on August 24, 2010, 11:39:23 am
I'm not into C# at all(learning C++) but I found this.
http://www.dotnetuncle.com/csharp/118_array.aspx
and this
http://forums.sureshkumar.net/vb-asp-net-interview-technical-questions/16584-c-can-you-store-multiple-data-types-system-array.html
Title: Re: [RESOLVED][C#] Multi Variable Array/List?
Post by: G_G on August 24, 2010, 11:42:05 am
Even though thats in visual basic, I figured it out. Dunno why I didn't think of it. Just make a list or an array with object set as the argument or whatever.
List<object> multi_data_array = new List<object>();
object[] multi_data_array2 = new object[array_size];


Thanks stripe. Resolved.
Title: Re: [RESOLVED][C#] Multi Variable Array/List?
Post by: Blizzard on August 24, 2010, 11:49:50 am
Though I wouldn't recommend using multi-type arrays. It's a pretty bad and dirty concept in itself. Used properly types arrays whenever you can. In fact, there is no need for multi-type arrays if the code was structured well. Only badly structured code needs multi-type arrays of types that are completely different (rather than an array with instances that share the same base class up to some point).
Title: Re: [RESOLVED][C#] Multi Variable Array/List?
Post by: G_G on August 24, 2010, 12:03:56 pm
Well basically I'm converting data. I'm sure you've looked how sloppy the pokemon starter data is. Some of the config files just have long huge lines. I'm sure I could find a better way of doing this but this seems to work just fine.