G
Guest
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.
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.