VB.NET equivalent to C#'s using directive

独自空忆成欢 提交于 2019-12-08 17:33:50

问题


I am converting some code from C# to VB.NET, and I need to know what the equivalent is for C#'s using directive.

Update: Sorry, but so far I haven't gotten my answer. Here is a C# example:

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

namespace ReportGen
{
    class Reports

回答1:


You're looking for the Imports statement. Place any import statements that you need at the very top of your code file, just like the using directive in C#:

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

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



回答2:


Here is a link showing a syntax comparison between C# and VB.NET side by side.

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):

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



回答3:


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

see: Global Import/using Aliasing in .NET




回答4:


"Using" with a capital U



来源:https://stackoverflow.com/questions/4134472/vb-net-equivalent-to-cs-using-directive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!