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.