VB к функциям C#

Если Ваше использование PHP и MySQL, можно использовать mysql_insert_id () функция, которая скажет Вам идентификатор объекта Вы Просто instered.
, Но без Вашего Языка и DBMS я просто стреляю в темноте здесь.

40
задан 3 revs, 2 users 100% 10 April 2010 в 18:53
поделиться

11 ответов

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 : если массив имеет нулевую длину, GetUpperBound вернет -1, а Length вернет 0. UBound () в VB.NET вернет -1 для нулевой длины массивы.
  • Строковые функции VB используют индекс, основанный на единице, тогда как метод .NET использует индекс, основанный на нуле. То есть Mid ("asdf", 2,2) соответствует "asdf" .SubString (1,2) .
  • ? не является точным эквивалентом IIf , потому что IIf всегда оценивает оба аргумента, а ? оценивает только тот, который ему нужен. Это может иметь значение, если есть побочные эффекты оценки ~ дрожь!
  • Многие классические строковые функции VB, включая Len () , UCase () , ] LCase () , Right () , RTrim () и Trim () , будут обрабатывать аргумент Nothing ( Null в C #) как эквивалент строки нулевой длины. Выполнение строковых методов для Nothing , конечно же, вызовет исключение.
  • Вы также можете передать Nothing классическому VB Mid () и ] Replace () функции. Вместо того, чтобы генерировать исключение, они вернут Nothing .
80
ответ дан 27 November 2019 в 01:21
поделиться
  • 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
ответ дан 27 November 2019 в 01:21
поделиться

Если вы посмотрите на MSDN, вы увидите, что в большинстве случаев есть примеры кода для обоих языков.

0
ответ дан 27 November 2019 в 01:21
поделиться

Another one...

VB - IsDBNull(value)

C# - yourdatarow.IsNull("columnName")

1
ответ дан 27 November 2019 в 01:21
поделиться

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.

1
ответ дан 27 November 2019 в 01:21
поделиться

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
2
ответ дан 27 November 2019 в 01:21
поделиться

IIf (test, trueval, falseval) >> (тест? Trueval: falseval);

IsNothing (obj) >> (obj == null);

UCase (str) >> str.ToUpper ();

LCase (str) >> str.ToLower ();

2
ответ дан 27 November 2019 в 01:21
поделиться

Большинство из них будут методами экземпляра строкового объекта, которые возвращают измененную строку.

MsgBox vs. MessageBox.Show(..)
IIF vs. (expression?returnValueIfTrue:returnValueElse)
2
ответ дан 27 November 2019 в 01:21
поделиться

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

3
ответ дан 27 November 2019 в 01:21
поделиться
UBound()  "array".Length
LBound()
IsNothing(): "object" == null
Chr()     (char)"N"
Len()     "string".Length
UCase()   "string".ToUpper()
LCase()   "string".ToLower()
Left()    "string".Substring(from, to)
Right()   "string".Substring(from, to)
RTrim()   "string".TrimEnd()
LTrim()   "string".TrimStart()
Trim()    "string".Trim()
Mid()     "string".Substring(from, to)
Replace() "string".Replace()
Split()   "string".Split()
Join()    String.Join()
MsgBox()  MessageBox.Show()
IIF()     validate ? iftrue : iffalse;
4
ответ дан 27 November 2019 в 01:21
поделиться

Вы найдете преобразование для многих из этих функций на этой странице википедии .

1
ответ дан 27 November 2019 в 01:21
поделиться
Другие вопросы по тегам:

Похожие вопросы: