I have a couple of lists. I want to loop through the lists, compare them and display the output on a separate lines in C#. I'd appreciate input.
For example 'A' can be found between 1-4 and 'B' is listed between 4-7. Therefore, 'A' & 'B' can be found within the range of 1-7. 'C' & 'D' can be acquired within the range 8-9.
'C' occurs between 8 & 9 and 'D' starts at 9.
Input:
List1: '1-4', '4-7', '8-9', '9-10'
List2: 'A', 'B', 'C', 'D'
Output:
1-4 A
4-7 A, B
8-9 C
9-10 C, D
I tried this and not getting the desired output.
List<string> output = new List<string>();
for (int i = 0; i < List1.Count; i++)
{
if (List2.Count <= i + 1)
{
output.Add($"{List1} {List2}");
}
}
For example 'A' can be found between 1-4 and 'B' is listed between 4-7. Therefore, 'A' & 'B' can be found within the range of 1-7. 'C' & 'D' can be acquired within the range 8-9.
'C' occurs between 8 & 9 and 'D' starts at 9.
Input:
List1: '1-4', '4-7', '8-9', '9-10'
List2: 'A', 'B', 'C', 'D'
Output:
1-4 A
4-7 A, B
8-9 C
9-10 C, D
I tried this and not getting the desired output.
List<string> output = new List<string>();
for (int i = 0; i < List1.Count; i++)
{
if (List2.Count <= i + 1)
{
output.Add($"{List1} {List2}");
}
}