how do i malloc in c# windowform?
-
hi i am trying to do malloc in vs.net 2005 c# window form as i am trying to dynamically allocate memory for a array which i dont know the size. am i missing a reference or something? or is there some other way to do it? please advice
neodeaths wrote:
is there some other way to do it?
A simple declaration might look like this;
string[,] names = new string[5,4];
More information and examples can be found on MSDN[^]. --edit If you don't know the size beforehand, there's two options;
I'd go for a generic list; it's dynamic and can be easily converted[^] to an array.
I are Troll :suss:
-
hi i am trying to do malloc in vs.net 2005 c# window form as i am trying to dynamically allocate memory for a array which i dont know the size. am i missing a reference or something? or is there some other way to do it? please advice
if you don't know the size, how on earth is malloc going to be any good? may I suggest you buy and study a beginners book on C# (or any language you choose), so you get the basics explained in a thorough and consistent way. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
hi i am trying to do malloc in vs.net 2005 c# window form as i am trying to dynamically allocate memory for a array which i dont know the size. am i missing a reference or something? or is there some other way to do it? please advice
The only reason to use malloc would be if you're passing stuff to unmanaged code. If all you want is an array, you just need to declare it. you don't have to worry about memory management the way you do with C.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
hi i am trying to do malloc in vs.net 2005 c# window form as i am trying to dynamically allocate memory for a array which i dont know the size. am i missing a reference or something? or is there some other way to do it? please advice
use a dynamic List<> or an ArrayList or any of the other nice things build into the .Net Framework (can be found under the System.Collections and System.Collections.Generic namespaces) And then start thinking in .Net! Buy a book, learn the basics. Don't get confused by the "C-style syntax" of C# - this IS NOT C in any way!