我有两列。一列包含字符串值,另一列包含十进制值。我想通过选择字符串值来选择十进制值。
string decimal
Jewel 10
Hasan 20
如何选择 Jewel,使其返回 10?
试试这个:
Dim selectedValues As List(Of InvoiceSOA)
selectedValues = DisputeList.FindAll(Function(p) p.ColumnName = "Jewel")
或者,如果您需要第一次出现“Jewel”,请使用:
Dim selectedValue As InvoiceSOA
selectedValue = DisputeList.Find(Function(p) p.ColumnName = "Jewel")
Dim selectedValue As InvoiceSOA = DisputeList.Find(Function(p)
if p.ColumnName = "Jewel" then
return true
end if
end function)
枚举功能是解决这个问题的正确方法。
例子:
Public Enum Ornaments
Neclace = 10
Bangle = 20
TieClip = 30
End Enum
如何使用这个枚举
Dim SelectedOrnament As Ornaments = Ornaments.Bangle
Select Case SelectedOrnament
Case Ornaments.Neclace
MsgBox("Your ornament is: " & Ornaments.Neclace)
Case Ornaments.Bangle
MsgBox("Your ornament is: " & Ornaments.Bangle)
Case Ornaments.TieClip
MsgBox("Your ornament is: " & Ornaments.TieClip)
Case Else
MsgBox("I could not find your ornament. Sorry")
End Select