Re: How to allocate memory in c#
- From: "Bob Powell [MVP]" <bob@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 04 Oct 2007 22:01:15 +0200
Stop working so hard. Use a collection!
Don't use arrays of things, use a generic collection such as List<B>.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
gol wrote:
Hi all,.
I want to know how to allocate memory in c#? Or, maybe I don't need to do it. I'm quite new to c#, so I don't know many things.
Now, this is what I have in c#:
class A
{
private B[] MyArray;
private static int NumberofRecords = 0;
private int ArraySize = 10;
public A()
{
MyArray = new B[ArraySize];
}
public void AddRecord(string str)
{
MyArray [NumberofRecords] = new B(str);
NumberofRecords++;
if (NumberofRecords == ArraySize - 1)
{
ArraySize += 10;
RecordsArray = new B[ArraySize];
}
}
}
To clarify, the method AddRecord is the only place where the array grows bigger. Class B has a constructor receiving a string.
I guess my code is wrong here, anyhow this is the functionality that I want.(being able to let the array grow bigger, define exactly how much bigger, and not to "lose" what I had before).
Please help,
Thank you very much.
- Follow-Ups:
- Re: How to allocate memory in c#
- From: Kevin Spencer
- Re: How to allocate memory in c#
- Prev by Date: How to create vertical menu strip using C#
- Next by Date: Re: MFC vs .NET
- Previous by thread: How to create vertical menu strip using C#
- Next by thread: Re: How to allocate memory in c#
- Index(es):
Relevant Pages
|