如何将此构造函数转换为C#

本文关键字:转换 构造函数 | 更新日期: 2023-09-27 18:05:57

不知道如何将Me.Base转换为C#

Imports Microsoft.VisualBasic  
Public Class ReplaceHTML  
    Inherits System.IO.Stream  
    Private Base As System.IO.Stream  
    Public Sub New(ByVal ResponseStream As System.IO.Stream)  
        If ResponseStream Is Nothing Then 
           Throw New ArgumentNullException("ResponseStream")  
        Me.Base = ResponseStream  
    End Sub  
End Class  

完整代码在这里

谢谢!

如何将此构造函数转换为C#

尝试使用this.Base

this告诉使用类的当前实例

编辑:

对于你更新的问题,我认为它应该看起来更像

public class ReplaceHTML : System.IO.Stream
{
    private System.IO.Stream Base;
    public ReplaceHTML(System.IO.Stream ResponseStream)
    {
        if (ResponseStream == null)
        {
            throw new ArgumentNullException("ResponseStream");
        }
        this.Base = ResponseStream;
    }
}

试试这个:

public YourClass(System.IO.Stream ResponseStream)
{
    if (ResponseStream == null)
    {
        throw new ArgumentNullException("ResponseStream");
    }
    // the "this" is optional here but I left it to show
    // that it is the equivalent of VB's "Me"
    this.Base = ResponseStream;
}
this.Base

那应该是Me.Base