哪些是相当于从VB.Net到C#的以下运算符?
> UBound()
> LBound()
> IsNothing()
> Chr()
> Len()
> UCase()
> LCase()
> Left()
> Right()
> RTrim()
> LTrim()
> Trim()
>中()
> 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")
笔记
> yourArray.GetUpperBound(0)vs yourArray.Length:如果数组为零长度,GetUpperBound将返回-1,而Length将返回0.UBound()在VB.NET中将为零长度数组返回-1。> VB字符串函数使用基于索引的索引,而.NET方法使用基于零的索引。也就是说Mid(“asdf”,2,2)对应于“asdf”.SubString(1,2)。>?不是IIf的确切等价物,因为IIf总是评估两个参数,和?只评估它所需要的。这可能很重要,如果有评价的副作用〜shudder!>许多经典的VB字符串函数,包括Len(),UCase(),LCase(),Right(),RTrim()和Trim(),将处理一个Nothing零长度字符串。对Nothing运行字符串方法当然会抛出异常。>您还可以将Nothing传递给经典的VB中()和Replace()函数。而不是抛出异常,这些将返回Nothing。