Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

Need Help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
yoshitha - 20 Dec 2005 09:59 GMT
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
Truong Hong Thi - 20 Dec 2005 10:05 GMT
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.
Ignacio Machin ( .NET/ C# MVP ) - 20 Dec 2005 14:04 GMT
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,

Signature

Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

> Hi
>
[quoted text clipped - 41 lines]
> thanks
> Jyothi

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.