匹配列表中的条件 [英] matching a condition in a list

查看:81
本文介绍了匹配列表中的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一个可以有很多不同匹配的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

推荐答案

Hi Mashahiro


看看精选案例,在我看来你想做什么。

http://msdn.microsoft.com/library/de...SelectCase.asp


我希望这就是你在找什么?


Cor
Hi Mashahiro

Have a look at the select case, that does what you want in my opinion.

http://msdn.microsoft.com/library/de...SelectCase.asp

I hope this was what you where looking for?

Cor


* Masahiro Ito< ma ** @ pleasespamgoaway.it> scripsit:
* Masahiro Ito <ma**@pleasespamgoaway.it> scripsit:
我正在尝试做一个可以有很多不同匹配的if语句。
在sql中我会这样做:

SELECT *
来自客户
员工进入(10,15,23,14)
在VB中,我会这样做:

如果Staff.Count = 10或员工.Count = 15或Staff.Count = 23或
Staff.Count = 14然后
Console.writeline(Staff.Count.tostring)
结束如果

是有没有办法匹配列表,没有使用arraylist,
集合,icomparer?

我有一个布尔值,列表中有十几个布尔变量。我可以用布尔值来做吗?

即:

if(b1,b2,b3,b4,b4)= False然后
Console.writeline(至少其中一个变量是假的)
结束如果
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




快速又脏话:


\\\

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/>


> >有没有办法匹配列表,不使用arraylist,
> > Is there any way to match to a list, without using an arraylist,
collection,icomparer?
collection, icomparer?


Array.Sort(SetItems)<返回(Array.BinarySearch(SetItems,Item)> = 0)

Array.Sort(SetItems)
Return (Array.BinarySearch(SetItems, Item) >= 0)




我觉得这很有趣。


Cor



I find it a funny solution however.

Cor


这篇关于匹配列表中的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆