Object cast exception at runtime

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

Hi,

I have a project "GrabTritonData_HiFreq" that uses some functions that
are frequently used. Therefore, I've created a separate project
"LibraryCommon" that contains these functions. One of the functions in
"LibraryCommon" is "FindInitialLow".

I call the function "FindInitialLow" in "LibraryCommon" from
"GrabTritonData_HiFreq", and it seems that there is an issue with
object casting in "FindInitialLow".

Details are below:

// Each item in mHistBucketList is "Bucket" type.
// Since this is called from "GrabTritonData_HiFreq" project,
// it's therefore, "GrabTritonData_HiFreq.Bucket" type
private Bucket FindInitialLow (ArrayList mHistBucketList,
double mThreshold)
{
Bucket mInitialLow = null;

// Exception here -- dp is of type "LibraryCommon.Bucket"
in debugger, while each item
// in mHistBucketList is "GrabTritonData_HiFreq.Bucket"
type
foreach (Bucket dp in mHistBucketList)
{
// Code omitted here
}
return mInitialLow;
}

Any suggestion on how to get this resolved? Thanks.
 
If you're using 2.0 or above.

You don't have to use an ArrayList.

You can use Generics.


List<Employee> myEmployees = new List<Employee>();

Where Employee is a class.


You can look at this as well.

private string ReportType(object o)
{

return o.GetType().ToString();

}

That'll probably tell you what the object is.
 
Back
Top