Object cast exception at runtime

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.
 
S

sloan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top