SelvaOnline

Hi,

How to increase the length of DirectoryInfo[]


Regards,
Selva
www.selvaonline.com



Re: Visual C# General How to increase the length of DirectoryInfo[]

ahmedilyas

Sorry, can you explain further What do you mean by increasing the length of DirectoryInfo[]

DirectoryInfo[] declaration is just an array of DirectoryInfo objects






Re: Visual C# General How to increase the length of DirectoryInfo[]

boban.s

That is not alowed in C#. You can do it with creating new array with new dimension and copy all elements of current array.
But Why do you need such thing with DirecoryInfo array.






Re: Visual C# General How to increase the length of DirectoryInfo[]

SelvaOnline

hi,
Actually i want to convert following two lines in to c#. please tell me how can i go ahead

ReDim Preserve DirectoryInfos(UBound(DirectoryInfos) + 1)

DirectoryInfos(jcount - 1) = objDirInfo


Regards,
Selva
www.selvaonline.com





Re: Visual C# General How to increase the length of DirectoryInfo[]

timvw

You could initialize a new array of n+1 elements, use Array.Copy to copy the first n elements, and then assign the last element.

But it makes more sense to use something that can grow dynamically like List<DirectoryInfo>, this way you can simply Add elements...





Re: Visual C# General How to increase the length of DirectoryInfo[]

Mattias Sjogren

timvw wrote:
You could initialize a new array of n+1 elements, use Array.Copy to copy the first n elements, and then assign the last element.

Or just call Array.Resize which does all of that for you.