Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将vb.net中的一些代码重写为c#_C#_Vb.net - Fatal编程技术网

将vb.net中的一些代码重写为c#

将vb.net中的一些代码重写为c#,c#,vb.net,C#,Vb.net,我有一些我之前在VB.NET中编写的代码 Dim zippedLogFileName = f.FullName + ".gz" Try Using inputStream = f.OpenRead(), zipFileStream = File.Create(zippedLogFileName), compressionStream = New GZipStream(z

我有一些我之前在VB.NET中编写的代码

            Dim zippedLogFileName = f.FullName + ".gz"
        Try
            Using inputStream = f.OpenRead(),
                zipFileStream = File.Create(zippedLogFileName),
                compressionStream = New GZipStream(zipFileStream, CompressionMode.Compress)
                inputStream.CopyTo(compressionStream)
            End Using
        Catch ex As IOException
        End Try
我正在努力学习c。但无法将其重写为c。 谁能帮我

            var zippedLogFileName = f.FullName + ".gz";
        try {
            using {

            }


        catch IOException ex { }
        }
你是想说

using(var inputStream = f.OpenRead()) {
    ...
}

您可以尝试使用将代码从VB更改为C#

我建议您使用.NET Reflector。 它将允许您反编译整个编译后的VB.NET项目,并自动将其重写为C#for your:)。
当然,它不包含注释,函数的名称是假的,但当您必须进行转换时,这是一个非常好的起点。

作为旁注,如果您在VB.NET中编译了(exe/dll)代码,试着用ILSpy打开它,你会看到它在C#Additional sidenote中是怎样的-通常认为在try-catch块中不做任何异常都是不好的形式(即catch(IOExpection ex){})。试着用转换器转换它。:)它不起作用。它起作用了,若你们在很多年后从行尾去掉逗号,但读者应该知道这个答案是不正确的。转换应该有3个嵌套的“using”块-VB允许一次指定多个“using”主题,但C#不允许。
string zippedLogFileName = f.FullName + ".gz";
try{
    using(var inputStream = f.OpenRead())
    {
          var zipFileStream = File.Create(zippedLogFileName);
          var compressionStream = New GZipStream(zipFileStream,  CompressionMode.Compress);
          inputStream.CopyTo(compressionStream);
     }
}
catch(IOException ex)
{
   // don't bury exceptions but rather handle them where most appropriate
}