Thursday, March 15, 2012

How to change the array size at runtime in c#

Here i will show how to accept array size at run time and accepting elements in asp.net,Providing size of array at run time called"Dynamic array".This can be implemented in vb.net using "ReDim statement".
For the performance based static array provides better performance compare with custom array.The dynamic array should be used when array size changed at run time

c#:
submain();
byte[] a = null;
byte n = 0;
byte i = 0;
FileSystem.WriteLine("enter arrary size:");
n = ReadLine();
a = new byte[n];
FileSystem.WriteLine("Enter Elelments");
for (i = 0; i <= a.lenth - 1; i++) {
 a[i] = ReadLine;
}
VB:
submain()
Dim a() as byte
Dim n,i as byte
writeline("enter arrary size:")
n=ReadLine()
ReDim a(n-1)
WriteLine("Enter Elelments")
for i=0 to a.lenth-1
a(i)=ReadLine
Next

No comments:

Bel