error on vb.net to c# conversion

I'm trying to convert some code written in VB.NET to C# and am getting this error:

Compiler Error Message: CS0118: 'ASP.filename_aspx.localCart' denotes a 'field' where a 'method' was expected

Here's my code:

for(i = 0; i <= Information.UBound((System.Array)localCart, 2); i += 1)
{
if (Convert.ToString(localCart(CARTID, i)) != "")
{
orderTotal = orderTotal + (Convert.ToDouble(localCart(CARTPPRICE, i)) * Convert.ToDouble(localCart(CARTPQUANTITY, i)));
//do something
}

The error is point to this line: if (Convert.ToString(localCart(CARTID, i)) != "")

Any solutions



Answer this question

error on vb.net to c# conversion

  • Origamime

    You've got parenthesis and brackets mixed up. It looks like localCart is an array, so you should be using localCart[CARTID, i] instead of localCart(CARTID,i). C# uses brackets for indexed access to arrays, where Visual Basic uses parenthesis.
  • andplo

    localCart(CARTID, i)

    VB uses () for array indexes, and C# uses [ ]. Try localCart[CARTID, i], as it stands, your code is looking for a method called localCart. Which is why it says that localCart is not a method, but your code thinks that it is.



  • error on vb.net to c# conversion