VB to C# Functions

后端 未结 14 1019
忘了有多久
忘了有多久 2020-12-02 06:51

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

  • UBound()
  • LBound()
  • IsNothing()
  • <
相关标签:
14条回答
  • 2020-12-02 07:28

    All these functions are member methods of the Microsoft.VisualBasic.Information class, in the Microsoft.VisualBasic assembly, so you can use them directly. However, most of them have C# equivalents, or non language specific equivalents in core .NET framework classes :

    • UBound() : Array.GetUpperBound
    • LBound() : Array.GetLowerBound
    • IsNothing() : == null
    • Chr() : (char)intValue (cast)
    • Len() : String.Length
    • UCase() : String.ToUpper
    • LCase() : String.ToLower
    • Left(), Right() and Mid() : String.Substring (with different arguments)
    • RTrim() : String.TrimEnd
    • LTrim() : String.TrimStart
    • Trim() : String.Trim
    • Replace() : String.Replace
    • Split() : String.Split
    • Join() : String.Join
    • MsgBox() : MessageBox.Show
    • IIF() : condition ? valueIfTrue : valueIfFalse (conditional operator)

    Links

    • Array members
    • String members
    • MessageBox.Show
    • conditional operator
    0 讨论(0)
  • 2020-12-02 07:31
    • UBound() -> if x is an array of string[] for example: x.GetUpperBound();
    • LBound() -> if x is an array of string[] for example: x.GetLowerBound();
    • IsNothing() -> if (x == null)
    • Chr() -> char x = (char)65;
    • Len() -> x.Length();
    • UCase() -> assume x is a string: x.ToUpper();
    • LCase() -> assume x is a string: x.ToLower();
    • Left() -> assume x is a string: x.Substring(0, 10); // first 10 characters
    • Right() -> assume x is a string: x.Substring(x.Length - 10); // last 10 characters
    • RTrim() -> x.TrimEnd();
    • LTrim() -> x.TrimStart();
    • Trim() -> x.Trim();
    • Mid() -> assume x is a string: x.Substring()
    • Replace() -> assume x is a string: x.Replace();
    • Split() -> assume x is a string: x.Split();
    • Join() -> String.Join();
    • MsgBox() -> MessageBox.Show();
    • IIF() -> ternary operator (x == true ? true-value : false-value);
    0 讨论(0)
提交回复
热议问题