vb.net VB.NET中List.Find的使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14681642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use of List.Find in VB.NET
提问by Syed Md. Kamruzzaman
I have two columns. One column contains string values and another column contains decimal values. I want to select the decimal value by selecting the string value.
我有两列。一列包含字符串值,另一列包含十进制值。我想通过选择字符串值来选择十进制值。
string decimal
Jewel 10
Hasan 20
How do I select Jewel so it will return 10?
如何选择 Jewel 使其返回 10?
回答by Andrey Gordeev
Try this:
尝试这个:
Dim selectedValues As List(Of InvoiceSOA)
selectedValues = DisputeList.FindAll(Function(p) p.ColumnName = "Jewel")
Or, if you need the first occurence of "Jewel" use this:
或者,如果您需要第一次出现“Jewel”,请使用以下命令:
Dim selectedValue As InvoiceSOA
selectedValue = DisputeList.Find(Function(p) p.ColumnName = "Jewel")
回答by Badz
Dim selectedValue As InvoiceSOA = DisputeList.Find(Function(p)
if p.ColumnName = "Jewel" then
return true
end if
end function)
回答by Venkat
The Enum functionality is the right way to use for this question.
Enum 功能是解决这个问题的正确方法。
Example:
例子:
Public Enum Ornaments
Neclace = 10
Bangle = 20
TieClip = 30
End Enum
How to use this 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