VB到C#功能 [英] VB to C# Functions

查看:105
本文介绍了VB到C#功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪些是以下运营商相当于从VB.Net到C#?




  • UBound函数()

  • LBOUND()

  • IsNothing()

  • CHR()

  • 莱恩()

  • 用Ucase()

  • LCASE()

  • <李>左()
  • 右键()

  • RTrim时()

  • LTrim时()

  • TRIM()

  • 中()

  • 替换()

  • 斯普利特()

  • 加入()

  • MSGBOX()

  • IIF()


解决方案

  VB C#

UBound函数() = yourArray.GetUpperBound(0)或yourArray.Length用于单时二维阵列
LBOUND()= yourArray.GetLowerBound(0)
IsNothing()= Object.ReferenceEquals(物镜,空)
CHR()= Convert.ToChar()
莱恩()=串。长度
用Ucase()=字符串.ToUpper()
LCASE()=字符串.ToLower ()
左()=字符串.Substring(0,长度)
右键()=字符串.Substring(串。长度 - desiredLength)
RTrim时()= 串.TrimEnd()
LTrim时()=字符串.TrimStart()
微调()=(字符串.Trim()
中)=字符串.Substring (开始,长度)
将()=字符串.Replace()
斯普利特()=字符串.Split()
加入()=的string.join()
MSGBOX()= MessageBox.Show()
IIF()=(boolean_condition? 真:假)

备注




  • yourArray.GetUpperBound(0) VS yourArray.Length :如果数组是零长度,GetUpperBound将返回-1,而长度将返回0 UBound函数()在VB.NET将返回-1零-length数组。

  • VB的字符串函数采用的是一体的索引,而.NET方法使用从零开始的索引。即 MID(ASDF,2,2)对应ASDF.SubString(1,2)

  • 不是 I如果的完全等效,因为 I如果始终计算的两个的参数,和只计算它需要之一。如果有评估的副作用〜不寒而栗!

  • 许多经典的VB字符串函数,包括莱恩()<这可能关系/ code>,用Ucase() LCASE()右键() RTrim时() TRIM(),将把<$的参数C $ C>没有在C#中)为相等于一个零长度字符串。在没有运行字符串的方法当然会,抛出异常。

  • 您还可以通过没有经典VB 中()替换()功能。而不是抛出一个异常,这将返回没有


Which are the equivalent of the following operators from VB.Net to C#?

  • UBound()
  • LBound()
  • IsNothing()
  • Chr()
  • Len()
  • UCase()
  • LCase()
  • Left()
  • Right()
  • RTrim()
  • LTrim()
  • Trim()
  • Mid()
  • Replace()
  • Split()
  • Join()
  • MsgBox()
  • IIF()

解决方案

VB             C#

UBound()     = yourArray.GetUpperBound(0) or yourArray.Length for one-dimesional arrays
LBound()     = yourArray.GetLowerBound(0)
IsNothing()  = Object.ReferenceEquals(obj,null)
Chr()        = Convert.ToChar()
Len()        = "string".Length
UCase()      = "string".ToUpper()
LCase()      = "string".ToLower()
Left()       = "string".Substring(0, length)
Right()      = "string".Substring("string".Length - desiredLength)
RTrim()      = "string".TrimEnd()
LTrim()      = "string".TrimStart()
Trim()       = "string".Trim()
Mid()        = "string".Substring(start, length)
Replace()    = "string".Replace()
Split()      = "string".Split()
Join()       = String.Join()
MsgBox()     = MessageBox.Show()
IIF()        = (boolean_condition ? "true" : "false")

Notes

  • yourArray.GetUpperBound(0) vs yourArray.Length: if the array is zero-length, GetUpperBound will return -1, while Length will return 0. UBound() in VB.NET will return -1 for zero-length arrays.
  • The VB string functions uses a one based index, while the .NET method uses a zero based index. I.e. Mid("asdf",2,2) corresponds to "asdf".SubString(1,2).
  • ? is not the exact equivalent of IIf because IIf always evaluates both arguments, and ? only evaluates the one it needs. This could matter if there are side effects of the evaluation ~ shudder!
  • The Many classic VB String functions, including Len(), UCase(), LCase(), Right(), RTrim(), and Trim(), will treat an argument of Nothing (Null in c#) as being equivalent to a zero-length string. Running string methods on Nothing will, of course, throw an exception.
  • You can also pass Nothing to the classic VB Mid() and Replace() functions. Instead of throwing an exception, these will return Nothing.

这篇关于VB到C#功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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