所有自动在线转换器都无法转换此代码。不幸的是,我对C#的简要了解也让我感到失望。该代码源自一个博客,链接自another of my questions。
以下是C#中的代码段;
var virtualFileDataObject = new VirtualFileDataObject();
virtualFileDataObject.SetData(new VirtualFileDataObject.FileDescriptor[]
{
new VirtualFileDataObject.FileDescriptor
{
Name = "abc.txt",
StreamContents = stream =>
{
using(var webClient = new WebClient())
{
var data = webClient.DownloadData("http://www.google.com");
stream.Write(data, 0, data.Length);
}
}
},
});
我目前使用VB.NET(删除了一些内联的东西);
Dim virtualFileDataObject = New VirtualFileDataObject()
Dim vf As New VirtualFileDataObject.FileDescriptor()
vf.Name = "abc.txt"
vf.StreamContents = ??
Using webc As New WebClient()
Dim data = webc.DownloadData("http://www.google.com")
stream??.Write(data, 0, data.Length)
End Using
virtualFileDataObject.SetData(vf)
非常感谢您的帮助!
答案 0 :(得分:0)
StreamContents
正在设置一个匿名方法,VB.NET不支持(但它在VB.NET 10中出现,它在.NET 4.0中出现)。我可以建议的最好的事情是:
vf.StreamContents = AddressOf(MyStreamContents)
Public Sub MyStreamContents(ByVal stream As <Whatever the type is>)
Using webc As New WebClient()
Dim data = webc.DownloadData("http://www.google.com")
stream.Write(data, 0, data.Length)
End Using
End Sub