Which are the equivalent of the following operators from VB.Net to C#?
Another one...
VB - IsDBNull(value)
C# - yourdatarow.IsNull("columnName")
If you look on MSDN you see that most of the time there are sample code for both languages.
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 );
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.
arrayVar.Length
Is Nothing
in VB.Net and == null
in C#Convert.ToChar()
or (char)someVar
stringVar.Length
use this in VB toostringVar.ToUpper()
use this in VB toostringVar.ToLower()
use this in VB toostringVar.Substring(0, n)
use this in VB toostringVar.Substring(stringVar.Length - n)
use this in VB toostringVar.TrimEnd()
use this in VB toostringVar.TrimStart()
use this in VB toostringVar.Trim()
use this in VB toostringVar.Substring(n, m)
use this in VB toostringVar.Replace()
use this in VB toostringVar.Split()
use this in VB tooString.Join()
use this in VB tooMessageBox.Show()
(condition) ? truepart : falsepart
- note that there are some differences, because "?" is an operator and not a functionI 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.
The space function is missing from everyone else's list:
Space(16) -> new String(" ", 16)