.net 选择案例问题

.net 选择案例问题,.net,vb.net,.net,Vb.net,我有以下代码: For each c as char in "Hello World" Select Case c Case "h" DoSomething() Case "e" DoSomething() End Select Next 为什么我不能这样写: Case "h" Or "e" DoSomething() 它表示“Long”值不能转换为“Char” 如何完成这项任务 Case "h", "e" DoSomething() 如果我记得我的VB(

我有以下代码:

For each c as char in "Hello World"
 Select Case c
  Case "h"
   DoSomething()
  Case "e"
   DoSomething()
  End Select
Next
为什么我不能这样写:

Case "h" Or "e"
 DoSomething()
它表示“Long”值不能转换为“Char”

如何完成这项任务

Case "h", "e"
   DoSomething()
如果我记得我的VB(这是可疑的)

错误消息似乎是由于它在两个字符串之间尝试按位“或”操作,这似乎是随机的。

使用:

Select Case c
  Case "h"
  Case "e"
    DoSomething()
End Select
或:


大小写试图在c上匹配,但c是字符,“h”或“e”是布尔表达式。但案例的类型必须与声明的select条件中的类型相同。

有关解决方案,请参见

这只是让Select语句不起作用。@Ash在C#中可能起作用。它们在VB中就是这样工作的,Cobold只是语法有点错误。您的解决方案是正确的,但操作不是随机的:它“对两个数值表达式执行位析取”。@Matt-我只是不明白为什么“h”或“e”是
长的
;pI猜测Or的结果是计算为long(但我认为这不应该编译)@Matt Turn
选项Strict On
,它不会编译。现在在VB设置中打开它,这样所有新项目都可以打开它@Marc看起来编译器很乐意发出代码将这些字符串强制为
Long
(尽管这些特定字符串会导致运行时错误),但不愿意将
(Long)或(Long)
强制为
Char
。一个人在这里可能会发疯,让我们都使用
选项Strict On
来代替:)是的,不相关的,按位表达式也与char:-)不匹配
Select Case c
  Case "h","e"
    DoSomething()
End Select
For each c as char in "Hello World"
    Select Case c.ToString 'When putting certain objects VB will true/false result of if the string is empty(false) or has text(true).
        Case "h", "E"
          DoSomething()
        Case "e", "H"
          DoSomethingElse()
    End Select
Next