Let me start by saying that I have read up on my problem, specifically this question and this one also. My problem is a little different, however. I understand the differences between the different methods, but cannot get my code to run correctly for the life of me.
In part of my code, I have the comparison below. But the comparison always fails, and "Type is:leg" prints out.
if (String.Compare(timer.Type,"leg",true) == 0)
{
timer.StopTime = DateTime.Now;
// TODO Log into database here
toRemove.Add(timer);
}
//Couple more conditions in here...
else
{
Console.WriteLine("Attempting to remove cycle timer of invalid type");
Console.WriteLine("Type is:" + timer.Type);
//TODO: Log error
}
I also tried alternative methods, but none of them seem to work for me.
if(timer.Type == "leg" || timer.Type == "Leg") //Fails
if(time.Type.Equals("leg") || timer.Type == "Leg") //Fails
String type = timer.Typer; //Worth a shot...
if(type == "leg" || type == "Leg") //No luck
EDIT: More code has been requested, so here is the entire method.
private void stopFinishedTimers(AGVData agv)
{
List<CycleTimer> toRemove = new List<CycleTimer>();
foreach (CycleTimer timer in AllRunningCycleTimers)
{
if (agv.CurrentRFIDNumber == timer.CycleStopRfid)
{
if (String.Compare(timer.Type,"leg",true) == 0)
{
timer.StopTime = DateTime.Now;
// TODO Log into database here
toRemove.Add(timer);
}
else if (timer.Type.Equals("route") || timer.Type.Equals("Route"))
{
timer.StopTime = DateTime.Now;
// TODO Log into database here
toRemove.Add(timer);
}
else
{
Console.WriteLine("Attempting to remove cycle timer of invalid type");
Console.WriteLine("Type is:" + timer.Type);
//TODO: Log error
}
}
}
Where CycleTimers are a class containing a fields called type, accessed through a property.