VB.NET If-Else在列表中 [英] VB.NET If-Else in List

查看:48
本文介绍了VB.NET If-Else在列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想知道VB.NET中是否有一种方法可以找到列表中是否存在特定值,或者可以在If-else条件下使用的方法.我现在正在做的就是使用这个:

I just want to know if there's an approach in VB.NET that can find if a specific value exist on a list or something which can use in my If-else condition. What I'm doing now is to use this:

If ToStatus = "1CE" Or ToStatus = "2TL" Or ToStatus = "2PM" Then
    'Do something
Else
    'Do something
End If

这很好用,但是将来如果我有数百个字符串要与 ToStatus 进行比较,该怎么办?这将是一场噩梦!现在,如果存在这样的功能,如何在语句中添加"And"和"Or"?

This works fine, but how if I have hundreds of string to compare to ToStatus in the future? It will be a nightmare! Now, if such functionality exists, how can I add "And" and "Or" in the statement?

提前谢谢!

推荐答案

您可以使用包含函数:

Dim someList = New List(Of String) From { ... }
If Not someList.Contains(ToStatus) Then

这篇关于VB.NET If-Else在列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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