Valhalla Legends Archive

Programming => General Programming => .NET Platform => Topic started by: Dyndrilliac on August 31, 2006, 01:59 PM

Title: [C++.NET] Variable length arrays?
Post by: Dyndrilliac on August 31, 2006, 01:59 PM
I've been trying to figure out how the correct syntax for creating a variable length array should go, and having very bad results. Here's what I've got:array<Byte>^ MyBuffer[(const UInt32)i_len+4] = {0};I also tried:All to no avail. Also MSDN spits up bunches of results in their Search utility with old syntax making it pretty worthless -.- I'm using .NET Framework 2.0 btw.
Title: Re: [C++.NET] Variable length arrays?
Post by: K on August 31, 2006, 03:17 PM
A good tip is when searching for .NET 2.0 things, search http://msdn2.microsoft.com instead of msdn.microsoft.com.  Also try using "C++/CLI" on google instead of "Managed C++" or "C++.NET"

Oh, and

array<Byte>^ myarray = gcnew array<Byte>(Len);


Just like in C#, all objects must be allocated with new;  to differentiate the managed new from the standard c++ new, it is called "gcnew" garbage collected new).


Edit:  the carrot symbol means an item is a pointer to a managed object, as opposed to a pointer to a regular object (*).  So to create an array of managed strings, you would do this:


array<String^>^ myarray = gcnew array<String^>(Len);

HTH
Title: Re: [C++.NET] Variable length arrays?
Post by: Dyndrilliac on August 31, 2006, 04:49 PM
Oh! Thanks for the info, now things make a lot more sense. I'm really starting to enjoy C++.net. The interoperability is really nice, as is garbage collection.