如何编写switch语句 [英] how to write a switch statement

查看:83
本文介绍了如何编写switch语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以这种方式在C#中为az转换vb的switch语句" < 选择 案例 Asc (" ") Asc ( z") strStringTyped = strStringTyped& _ Chr(KeyAscii)


"

感谢

解决方案

没有直接翻译:C#switch cases不能是值的范围.
您必须为每个单独的值提供一个理由.

switch(KeyAscii)
   {
   case '' '':
   case ''a'':
...
   case ''z'':
      strStringTyped = strStringTyped + KeyAscii.ToString();
      break;
   }

可能最好使用string.IsLetter等.


how to convert a switch statement of vb in c# for a-z in this way"

Select Case KeyAscii
  Case Asc(" ") To Asc("z")
    strStringTyped = strStringTyped & _
                           Chr(KeyAscii)


"

thanks

解决方案

There is no direct translation: C# switch cases cannot be a range of values.
You would have to provide a case for each individual value.

switch(KeyAscii)
   {
   case '' '':
   case ''a'':
...
   case ''z'':
      strStringTyped = strStringTyped + KeyAscii.ToString();
      break;
   }

Probably, you would be better using string.IsLetter as so forth.


这篇关于如何编写switch语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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