Welcome to APLNext Sign in | Join | Help
in
Community Website
Blogs Forums

Unexpected (unnecessary?) casting required

Last post 10-11-2006, 5:23 PM by Chris.McIntosh. 0 replies.
Sort Posts: Previous
  • Unexpected (unnecessary?) casting required

     10-11-2006, 5:23 PM

    I had a number of unexpected errors in an APLNext class library, which I finally tracked down to casting. Here is an example:

    When trying to use an undeclared variable as an index into an array in the expression below, I got an error/exception.

      for (Count=0; Count<FieldCount; Count++) {
       
    Fields[Count] ← MyDataTable.Columns[Count].ColumnName
      }

    The following is output from expressions in the Debugger's Watch window

    MyDataTable.Columns[Count].ColumnName
    ->
    The best overloaded match for 'System.Data.DataColumnCollection.this[int]' has some invalid arguments

    MyDataTable.Columns[0].ColumnName
    -> "ColumnName"

    Count.GetType()
    -> {Name = "Int32" FullName = "System.Int32"}

    0.GetType()
    ->{Name = "Int32" FullName = "System.Int32"}

    MyDataTable.Columns[(System.Int32)Count].ColumnName
    -> "ColumnName"

    As Count already seems to be an Int32, it shouldn't have to be recast in order for the expression to work.

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems