2010-11-09 80 views
7

我正在將一些代碼從C#轉換爲VB.NET,並且我需要知道C#的using指令是什麼。VB.NET等價於C#的使用指令

更新:對不起,但到目前爲止,我還沒有得到我的答案。下面是一個C#示例:

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

namespace ReportGen 
{ 
    class Reports 
+3

它是使用* *指令的未使用*語句*。 – 2010-11-09 15:05:24

+0

謝謝,我想知道。 – 2010-11-09 15:07:22

+5

這就是爲什麼幾乎每個問題都應該包含代碼片段:-) – 2010-11-09 15:12:35

回答

11

您正在尋找Imports聲明。將你需要在你的代碼文件的最頂端的任何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 
11

這是一個鏈接,顯示了C#和VB.NET並排的語法比較。

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

從鏈接:

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 

或者進口的語句(從網站也):

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 
-1

「使用」 用大寫的U