所以,我正在努力将此代码从 VB.NET 转换为 C#:
Public Class Form1
Const filesplit As String = "|split|"
Dim stub, opt() As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
On Error Resume Next
FileOpen(1, Application.ExecutablePath, OpenMode.Binary, OpenAccess.Read, OpenShare.Shared)
stub = Space(LOF(1))
FileGet(1, stub)
FileClose(1)
opt = Split(stub, filesplit)
End Sub
End Class
我使用了一系列在线转换器,但它们并不真正适合我。
我该怎么做?我正在尝试理解 VB.NET 源代码,以便我可以使用它。
最佳答案
这些方法位于 Microsoft.VisualBasic
命名空间中。
因此,您可以在项目中添加对此的引用,然后使用几乎完全相同的代码,并对所使用的方法进行少量额外限定:
using Microsoft.VisualBasic; //add this statement
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string filesplit = "|split|";
string stub;
string[] opt;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
FileSystem.FileOpen(1, Application.ExecutablePath, OpenMode.Binary, OpenAccess.Read, OpenShare.Shared);
stub = Strings.Space(Convert.ToInt32(FileSystem.LOF(1)));
FileSystem.FileGet(1, ref stub);
FileSystem.FileClose(1);
opt = Strings.Split(stub, filesplit);
}
}
}
但是,您应该真正考虑在 VB.NET 和 C# 代码中使用 System.IO
命名空间中的 File.xxx
方法,但这将导致让它为你工作。
关于c# - 如何在 C# 中使用 FileOpen (VB.NET)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25807898/