我有一个值数组
Dim result() As String = Split(values, ",")
'values'中的数据如下所示:
1576, 1589
1567, 1564
1555, 1570
1562, 1521
我想要做的是循环遍历数组,一次一行并比较值
if v1 (eg 1576) <= v2 (eg 1589) then record the number 1 in a separate variable, else 0
结果变量,记录的结果将如下所示:
1
0
1
0
答案 0 :(得分:3)
你可以使用LINQ来做到这一点:
Dim result() As String = (From i In values _
Let split = i.Split(",") _
Select If(Integer.Parse(split(0).Trim()) < Integer.Parse(split(1).Trim()), "1", "0")).ToArray()
答案 1 :(得分:0)
您可能希望将数组中的每对值存储为单个字符串,例如(伪代码):
dim dataArray as new List(Of String)
for each line as string in InputFile
dataArray.add(line)
Next
for each pair as string in dataArray
dim v1, v2 as integer
v1 = pair.Split(",")(0)
v2 = pair.Split(",")(1)
if v1 <= v2 then
Console.WriteLine("1")
Else
Console.WriteLine("0")
EndIf
Next
假设您正在从某种文件中读取这些值。如果你是,你也可以在阅读时进行比较。无论如何,这是一个快速而肮脏的解决方案。