Need Help

Y

yoshitha

Hi

in C#.net what is the equivalent function or anything for Redim preserve
statement

or can any one tell me the equivalent code for follwoing vb.net code.

(db is the object for database.vb class )

If DB.Run("Select * from TestInfo") Then
i = 0
While DB.Result.Read
ReDim Preserve iTestIDs(i)
strTestID = DB.Result("TestID")
iTestIDs(i) = Val(strTestID.Substring(5))
i = i + 1
End While
finalVal = (UserFunctions.MaxOf(iTestIDs) + 1)


and for the follwoing function



Shared Function MaxOf(ByVal Num() As Integer) As Integer

Dim temp As Integer
Dim i As Integer
If Num.Length > 1 Then
For i = 0 To UBound(Num) - 1
If Num(i) > Num(i + 1) Then
temp = Num(i)
Num(i) = Num(i + 1)
Num(i + 1) = temp
End If
Next

Return Num(UBound(Num))
Else
Return Num(0)
End If

End Function

plz can anybody help me i'm very new to c#.net.

thanks
Jyothi
 
T

Truong Hong Thi

Although you could write a custom function to mimic ReDim, the easiest
way is to use an ArrayList instead of normal array. It is in
System.Collections namespace.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

As Hong Thi suggested you better use an ArrayList for this , this is in the
case you need to keep ALL the values you read, if all you need is the
maximun then you better keep it in a temp variable and no use a collection
at all :
int maxValue= Int32.MinValue;
while( db.read() )
if ( Convert.ToInt32( db["TestID"]) > maxValue )
maxValue = Convert.ToInt32( db["TestID"]) ;

cheers,
 

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

Similar Threads


Top