在VB.NET中使用List.Find函数

9

我有两列数据。其中一列包含字符串值,另一列包含十进制值。我想通过选择字符串值来选择十进制值。

string          decimal
Jewel           10
Hasan           20

如何选择 Jewel,使其返回 10?

这是一个“List”还是什么?你如何存储你的列? - Andrey Gordeev
1
Dim DisputeList As List(Of InvoiceSOA) = db.GetList(Of InvoiceSOA)("OraclePackage", params)声明 DisputeList 为 InvoiceSOA 列表类型,并通过 db.GetList(Of InvoiceSOA)("OraclePackage", params) 方法获取数据。 - Syed Md. Kamruzzaman
1
什么是InvoiceSOA?请更新您的问题。 - Andrey Gordeev
1
它是一个包含列名的实体。 - Syed Md. Kamruzzaman
3个回答

39

试试这个:

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")

0
Dim selectedValue As InvoiceSOA = DisputeList.Find(Function(p) 
        if p.ColumnName = "Jewel" then
            return true
        end if
    end function)

0

枚举功能是解决这个问题的正确方法。

例如:

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

枚举索引允许使用十进制/双精度值吗? - Chase

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接