c# - 如何在 C# 中使用 FileOpen (VB.NET)?

标签 c# .net vb.net vb.net-to-c#

所以,我正在努力将此代码从 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/

相关文章:

vb.net - 使用VB.NET发送短信

c# - 将字符串从 c# 传递到 c++ dll

c# - 根据背景使前景颜色为黑色或白色

.net - Python,使用完整的.NET?

mysql - 将数据 GridView 行添加到 vb.net 中的 sql 表

vb.net - 在 Visual Studio/VB.Net 项目中使用 Mercurial

c# - 对于 XDocument 后代操作如何只返回直接子节点?

c# - 使用操作过滤器修改操作内的值

c# - 为什么 1000 个线程比几个线程快?

.net - 导出的 C 函数、结构和 .Net 编码(marshal)处理中 bool 的大小