VB to C# Functions

后端 未结 14 1018
忘了有多久
忘了有多久 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:16

    Another one...

    VB - IsDBNull(value)

    C# - yourdatarow.IsNull("columnName")

    0 讨论(0)
  • 2020-12-02 07:16

    If you look on MSDN you see that most of the time there are sample code for both languages.

    0 讨论(0)
  • 2020-12-02 07:16

    One more addition to this could be IndexOf() function to Find String within string

    An example below...

    string MainString = "String Manipulation"; 
    string SearchString = "pul"; 
    int FirstChr = MainString.IndexOf(SearchString); 
    //SHOWS START POSITION OF STRING 
    MessageBox.Show("Found at : " + FirstChr );
    
    0 讨论(0)
  • 2020-12-02 07:17

    First of all, most of those are NOT operators. They are functions, and the functions are only included in VB.Net for compatibility reasons. That means you shouldn't use them in VB.net either, and instead use the equivalents provided by the new API.

    • UBound()arrayVar.Length
    • LBound() — obsolete, lower bound is always 0 in a normal .Net array
    • IsNothing() — obsolete. Use Is Nothing in VB.Net and == null in C#
    • Chr()Convert.ToChar() or (char)someVar
    • Len()stringVar.Length use this in VB too
    • UCase()stringVar.ToUpper() use this in VB too
    • LCase()stringVar.ToLower() use this in VB too
    • Left()stringVar.Substring(0, n) use this in VB too
    • Right()stringVar.Substring(stringVar.Length - n) use this in VB too
    • RTrim()stringVar.TrimEnd() use this in VB too
    • LTrim()stringVar.TrimStart() use this in VB too
    • Trim()stringVar.Trim() use this in VB too
    • Mid()stringVar.Substring(n, m) use this in VB too
    • Replace()stringVar.Replace() use this in VB too
    • Split()stringVar.Split() use this in VB too
    • Join()String.Join() use this in VB too
    • MsgBox()MessageBox.Show()
    • IIF()(condition) ? truepart : falsepart - note that there are some differences, because "?" is an operator and not a function
    0 讨论(0)
  • 2020-12-02 07:23

    I believe some of these like Mid() are still available in the .NET Framework in the Microsoft.VisualBasic namespace which you can still reference from C# code.

    0 讨论(0)
  • 2020-12-02 07:27

    The space function is missing from everyone else's list:

    Space(16) -> new String(" ", 16)

    0 讨论(0)
提交回复
热议问题