问题描述
我正在尝试做一个可以有很多不同匹配的if语句。
在sql中我会这样做:
SELECT *
来自客户
员工进入(10,15,23,14)
在VB中,我会做:
如果Staff.Count = 10或Staff.Count = 15或Staff.Count = 23或
Staff.Count = 14那么
Console.writeline(Staff.Count.tostring)
结束如果
有没有办法匹配列表,不使用arraylist,
集合,icomparer?
我有一个布尔值,列有十几个布尔变量。我可以用布尔值来支付
吗?
ie:
if(b1,b2,b3) ,b4,b4)= False然后
Console.writeline(至少其中一个变量是假的)
结束如果
谢谢你的想法!
Masa
I am trying to do an if statement that could have many different matches.
In sql I would do it like:
SELECT *
FROM Customer
WHERE Staff IN (10, 15, 23, 14)
In VB, I would do:
If Staff.Count = 10 or Staff.Count = 15 or Staff.Count = 23 or
Staff.Count = 14 Then
Console.writeline(Staff.Count.tostring)
End If
Is there any way to match to a list, without using an arraylist,
collection, icomparer?
I have a boolean, with a list of a dozen boolean variables. Can I do it
with boolean as well?
ie:
if (b1, b2, b3, b4, b4) = False Then
Console.writeline("At least one of those variables was false")
End If
Thanks for ideas!
Masa
推荐答案
快速又脏话:
\\\
MsgBox(CStr(IsInSet(12,1,2,3,4,5,99,23,12,4,87))) />
MsgBox(CStr(IsInSet(12,1,2,3,4,5,99,23,13,4,87)))
..
..
..
公共共享函数IsInSet(ByVal Item As Object,ByVal ParamArray SetItems()As Object)As Boolean
Array.Sort(SetItems)
返回(Array.BinarySearch(SetItems,Item)> = 0)
结束函数
/ //
-
Herfried K. Wagner [MVP]
< URL:http://dotnet.mvps .org />
Quick and Dirty:
\\\
MsgBox(CStr(IsInSet(12, 1, 2, 3, 4, 5, 99, 23, 12, 4, 87)))
MsgBox(CStr(IsInSet(12, 1, 2, 3, 4, 5, 99, 23, 13, 4, 87)))
..
..
..
Public Shared Function IsInSet(ByVal Item As Object, ByVal ParamArray SetItems() As Object) As Boolean
Array.Sort(SetItems)
Return (Array.BinarySearch(SetItems, Item) >= 0)
End Function
///
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Array.Sort(SetItems)
Array.Sort(SetItems)
Return (Array.BinarySearch(SetItems, Item) >= 0)
我觉得这很有趣。
Cor
I find it a funny solution however.
Cor
这篇关于匹配列表中的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!