VB.NET等价于C#的使用指令
问题描述:
我正在将一些代码从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
答
您正在寻找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
答
这是一个链接,显示了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
答
“使用” 用大写的U
答
Imports moOutlook = Microsoft.Office.Interop.Outlook;
Imports moExcel = Microsoft.Office.Interop.Excel;
它是使用* *指令的未使用*语句*。 – 2010-11-09 15:05:24
谢谢,我想知道。 – 2010-11-09 15:07:22
这就是为什么几乎每个问题都应该包含代码片段:-) – 2010-11-09 15:12:35