Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, January 16, 2006 5:34 PM
hi, is there a build in function for UBOUND in c#? I am trying to convert from ASP to ASP.NET (C#) ... Any suggestion?? Thanks in advance.
All replies (14)
Monday, January 16, 2006 6:29 PM
check the length property...
Monday, January 16, 2006 8:12 PM
I sincerely hope you're not trying to mirror line for line between asp and asp.net. That's an easy way to get stuck in a royal pain.
Monday, January 16, 2006 10:08 PM
I don't know much about ASP, but I know there is a UBound function in the Microsoft.VisualBasic namespace.
Microsoft.VisualBasic.Information.UBound()
Thursday, February 2, 2006 2:31 PM
Does anyone have a solution for this? I'm having the same problem here. I converted the following piece of code using a conversion tool called Instrant C#, but I'm getting an error:
From VB.NET:
For i = 0 To UBound(localCart, 2)
If CStr(localCart(CARTID, i)) <> "" Then
orderTotal = orderTotal + (CDbl(localCart(CARTPPRICE, i)) * CDbl(localCart(CARTPQUANTITY, i)))
'do something
End If
Next
To C#:
int tempFor1 = localCart.GetUpperBound(1);
for (i = 0; i <= tempFor1; i++)
{
if (System.Convert.ToString(localCart(CARTID, i)) != "")
{
orderTotal = orderTotal + (System.Convert.ToDouble(localCart(CARTPPRICE, i)) * System.Convert.ToDouble(localCart(CARTPQUANTITY, i)));
//do something
}
}
The error message:
Compiler Error Message: CS0117: 'object' does not contain a definition for 'GetUpperBound'
I'm using ASP.NET 1.1. Please help!
Thursday, February 2, 2006 10:25 PM
Have you tried Microsoft.VisualBasic.Information.UBound()?
Thursday, February 2, 2006 10:57 PM
Change the declaration of "localCart" to be an array and the problem will go away.
As I mentioned in the other group, Instant C# can't get into the type inference game that the VB compiler performs when you don't type your variables.
Friday, February 3, 2006 2:16 AM
hi, is there a build in function for UBOUND in c#? I am trying to convert from ASP to ASP.NET (C#) ... Any suggestion?? Thanks in advance.
Hi,
Are you talking about the UBOUND of vbscript's array?
maybe you can use the GetUpperBound() in C#....
e.g.:
string[] myArray = new string[2];
myArray.GetUpperBound(0);
Friday, February 3, 2006 9:27 AM
Stop the madness!
Use the length property of the array, thats what it exists for.
Friday, February 3, 2006 11:04 AM
Yes - 'Length' is certainly the one to normally use - but for conversion purposes 'GetUpperBound' is the equivalent of VB's 'UBound' (since UBound does not equal length, and when you deal with multi-dimensional arrays, GetUpperBound is more useful).
But in this example, using 'Length' won't work either until the variable is declared as an array (VB really lets you get away with some very sloppy coding).
Friday, February 3, 2006 2:38 PM
Stop the madness!
Use the length property of the array, thats what it exists for.
QFT!!!! Listen to the prophet!
(fyi: collections have Count instead.)
Friday, February 3, 2006 3:30 PM
Infernal conversion! ;)
C# ain't scripting language ;) strong types are required.
To get solid conversion, you should probably use the length and include some Debug.Asserts.
With each array LBound or UBound you convert to use length, you will want to assert that the lower bound (with the method mentioned) is zero and the the upper bound is equal to the length.
If those assertions don't pass, then the array you are using is likely to cause issues in other places. When the conversion is compete and fully validated, you can remove the asserts
Wednesday, February 8, 2006 11:26 AM
Thanks guys. arrVals.GetUpperBound(0) solved the problem.
arrVals.Length gave this error:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
Thursday, June 25, 2009 4:42 AM
u can either include a reference to Microsoft.VisualBasic and use array.UpperBound(int i), where i is the value to want to check for
or use array.length and check for the value(i + 1)
Thursday, June 25, 2009 5:59 AM
Use 0 to yourArray.Items.Count()
something like
for (int c=0; c< yourArray.Items.Count(); c++)
{ };
Soumen, India