我正在将一些代码从C#转换为VB.NET,我需要知道C#的using指令的等价物。
更新抱歉,但到目前为止我还没有得到答案。这是一个C#示例:
using moOutlook = Microsoft.Office.Interop.Outlook;
using moExcel = Microsoft.Office.Interop.Excel;
namespace ReportGen
{
class Reports
答案 0 :(得分:12)
您正在寻找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
答案 1 :(得分: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
或者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
答案 2 :(得分:2)
Imports moOutlook = Microsoft.Office.Interop.Outlook;
Imports moExcel = Microsoft.Office.Interop.Excel;
答案 3 :(得分:-1)
“使用”大写字母U