dynamic arrays..//coming from Delphi

G

genc ymeri

Hi,
What can I use in C# for dynamic arrays ???? I have some records (struts in
..Net) and want to store them in a dynamic "arrays" or object list.

I noticed the in C# arrays' length can't be extented in run time. So, what
should I use ?

Thank You in advance.

PS:
In Delphi/Pascal I would do something like :

type
aEmployee = record
Name : string;
LastName : String;
DOB :TDatetime;
end;

var
OurListOfEmployees : array of aEmployee;
 
M

Michael Giagnocavo [MVP]

You can use an ArrayList. Or you can write your own array extending
(allocate new array, copy old items over).

-mike
MVP
 
D

DC

genc said:
// coming from Delphi
There are quite a lot of us here... said:
What can I use in C# for dynamic arrays ???? I have some records (struts in
.Net) and want to store them in a dynamic "arrays" or object list.

struct aEmployee
{
public string Name;
public string LastName;
public DateTime DOB;
}

....
....

ArrayList ourListOfEmployees = new ArrayList();

aEmployee emp;

emp = new aEmployee();
emp.Name = "Dejan";
ourListOfEmployees.Add(emp);

emp = new aEmployee();
emp.Name = "Genc";
ourListOfEmployees.Add(emp);

....
etc
....


LP,
Dejan
 
D

Daniel O'Connell [C# MVP]

DC said:
struct aEmployee
{
public string Name;
public string LastName;
public DateTime DOB;
}

I'd advise using a class here, otherwise when you unbox from the ArrayList,
you'll have to reinsert the object or your updates won't be maintained.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top