vbnet

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

VB.NET

VB.NET

VB.NET is a first-class citizen on .NET, sharing the same runtime/libraries as C#. While C# gets new syntax first, VB.NET remains supported in .NET 8+.
VB.NET是.NET平台的一等公民,与C#共享相同的运行时和类库。虽然C#率先获得新语法,但VB.NET在.NET 8及后续版本中仍受支持。

When to Use

适用场景

  • Legacy Migration: Porting VB6 apps to .NET.
  • Readability: Specific industries prefer the verbose, English-like syntax (
    End If
    ).
  • Office Automation: Integration with massive Excel/Access logic.
  • 遗留系统迁移:将VB6应用程序移植到.NET平台。
  • 可读性优先:特定行业偏好其 verbose、类英语的语法(
    End If
    )。
  • Office自动化:与大量Excel/Access逻辑集成。

Core Concepts

核心概念

Case Insensitivity

大小写不敏感

Dim X
and
dim x
are the same.
Dim X
dim x
是等效的。

Modules

模块(Modules)

Equivalent to static classes.
相当于静态类。

My Namespace

My命名空间

My.Computer
,
My.User
. Shortcuts for common tasks.
My.Computer
My.User
。是常见任务的快捷方式。

Best Practices (2025)

2025年最佳实践

Do:
  • Use
    Option Strict On
    : Disables implicit casting (critical for bugs).
  • Target .NET 8: Move away from .NET Framework 4.8.
  • Use String Interpolation:
    $"Hello {Name}"
    .
Don't:
  • Don't use
    On Error Resume Next
    : Use structured
    Try...Catch
    .
建议
  • 启用
    Option Strict On
    :禁用隐式类型转换(对排查bug至关重要)。
  • 目标.NET 8:脱离.NET Framework 4.8。
  • 使用字符串插值
    $"Hello {Name}"
不建议
  • 不要使用
    On Error Resume Next
    :使用结构化的
    Try...Catch

References

参考资料