简体   繁体   English

如何在C#中使用FileOpen(VB.NET)? 如何转换此代码?

[英]How do I use FileOpen (VB.NET) in C#? How do I convert this code?

So, I'm working on converting this code from VB.NET to C#: 所以,我正在努力将这个代码从VB.NET转换为C#:

FileOpen(1, Application.StartupPath & "\Stub.exe", _
    OpenMode.Binary, OpenAccess.Read, OpenShare.Default)

I've used a series of online converters, and they don't really work for me. 我使用过一系列在线转换器,它们并不适合我。

How do I do it? 我该怎么做? I'm trying to understand VB.NET source code so I can use it in. 我正在尝试理解VB.NET源代码,所以我可以使用它。

Use the following code. 使用以下代码。

BinaryReader br =
    new BinaryReader(
        new FileStream(Application.StartupPath + "/stub.exe",
        FileMode.Open,
        FileAccess.Read,
        FileShare.Read));

Look at the documentation . 看看文档 There are C# examples provided. 提供了C#示例。

The best solution is to redevelop the code using a BinaryReader . 最好的解决方案是使用BinaryReader重新开发代码。

If there's a lot of code and you are pressed for time, you could import Microsoft.VisualBasic into your C# project and then use Microsoft.VisualBasic.FileOpen . 如果有很多代码并且您需要时间,则可以将Microsoft.VisualBasic导入到C#项目中,然后使用Microsoft.VisualBasic.FileOpen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM