简体   繁体   English

VB.NET相当于C#的using指令

[英]VB.NET equivalent to C#'s using directive

I am converting some code from C# to VB.NET, and I need to know what the equivalent is for C#'s using directive. 我正在将一些代码从C#转换为VB.NET,我需要知道C#的using指令的等价物。

Update: Sorry, but so far I haven't gotten my answer. 更新:对不起,但到目前为止我还没有得到答案。 Here is a C# example: 这是一个C#示例:

using moOutlook = Microsoft.Office.Interop.Outlook;
using moExcel = Microsoft.Office.Interop.Excel;

namespace ReportGen
{
    class Reports

You're looking for the Imports statement. 您正在寻找Imports声明。 Place any import statements that you need at the very top of your code file, just like the using directive in C#: 将所需的任何import语句放在代码文件的最顶层,就像C#中的using指令一样:

Imports moOutlook = Microsoft.Office.Interop.Outlook
Imports moExcel = Microsoft.Office.Interop.Excel

Namespace ReportGen
   Public Class Reports
      'Your code here
   End Class
End Namespace

Here is a link showing a syntax comparison between C# and VB.NET side by side. 这是一个链接,显示了C#和VB.NET之间的语法比较。

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html http://www.harding.edu/fmccown/vbnet_csharp_comparison.html

From the link: 从链接:

Using reader As StreamReader = File.OpenText("test.txt")
  Dim line As String = reader.ReadLine()
  While Not line Is Nothing
    Console.WriteLine(line)
    line = reader.ReadLine()
  End While
End Using

Or the imports statement (from site also): 或者import语句(也来自站点):

Imports System 

Namespace Hello
   Class HelloWorld 
      Overloads Shared Sub Main(ByVal args() As String) 
         Dim name As String = "VB.NET" 

         'See if an argument was passed from the command line
          If args.Length = 1 Then name = args(0) 

          Console.WriteLine("Hello, " & name & "!") 
      End Sub 
   End Class 
End Namespace
Imports moOutlook = Microsoft.Office.Interop.Outlook; 
Imports moExcel = Microsoft.Office.Interop.Excel;

see: Global Import/using Aliasing in .NET 请参阅: .NET中的全局导入/使用别名

“使用”与大写U.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM