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

时间:2011-08-17 13:38:41

标签: c# vb.net

不知道如何将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  

完整代码为here

谢谢!

3 个答案:

答案 0 :(得分:6)

尝试使用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;
    }
}

答案 1 :(得分:4)

试试这个:

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;
}

答案 2 :(得分:3)

this.Base

那应该是Me.Base