I am trying to show the statusFinal value of the product by comparing two string time values.
Problem is, StartTimeNames: 9:00 to 9:45, status is blank (statusFinal value is not showing), and statusFinal value displays from 10:00 to the end time.
_vmModel.keyValuePairs
is a object of viewmodel Dictionary,
_vmModel.ProductTypesSel
is array of ProductType[] ,
_vmModel.StartTimeNames
is array of string[]
What's wrong with this code? Please see image.
Any help is appreciated. Thanks!
Dictionary<int, List<KeyValuePair<string, string>>> keyValuePairs = _vmModel.keyValuePairs;
foreach (var item in _vmModel.ProductTypesSel)
{
List<KeyValuePair<string, string>> temp = keyValuePairs[item.Code];
for (int i = 0; i < _vmModel.StartTimeNames.Length; i )
{
string filterStartTimeNames = _vmModel.StartTimeNames[i];
string statusFinal = "";
foreach (KeyValuePair<string, string> timeValue in temp)
{
if (filterStartTimeNames == timeValue.Key)
{
statusFinal = timeValue.Value;
Console.WriteLine("LoopCheck Nested Locked Value: " timeValue.Key);
}
else
{
Console.WriteLine("LoopCheck Nested Not Matched: " timeValue.Key);
}
}
Label statuslabel = new Label() { Text = statusFinal, WidthRequest = 80 };
}
}
CodePudding user response:
According to your description, there must be some logic mistakes in your code. The most simple and direct method to deal with the problem is debugging to find which line code has the result you didn't want.
Just add a break point at foreach (var item in _vmModel.ProductTypesSel)
. When the loop begin, run the code step by step and check the variable's value every time.
By checking the result of each line code is same as predicted, you can find where the problem is and resolve it.