C#中的等效My Function代码是什么

时间:2012-11-10 06:40:06

标签: c#

我想在VB.net代码下写到C#。什么是C#中最好的等效代码:

Private Sub AllControlDesign2(ByRef TB As Control)
    If TB.GetType Is GetType(StatusStrip) Then
        CType(TB, TextBox).ReadOnly = True
        TB.BackColor = stFromBackColour
        TB.ForeColor = Color.Gray
    End If
End Sub

3 个答案:

答案 0 :(得分:1)

我会这样做:

private void AllControlDesign2(Control tb) {
    var textBox = tb as TextBox;
    if (textBox != null) {
        textBox.ReadOnly = true;
        textBox.BackColor = stFromBackColour;
        textBox.ForeColor = Color.Gray;
    }
}

答案 1 :(得分:0)

这是从DeveloperFusion.com

复制的equivellant
private void AllControlDesign2(ref Control TB)
{
    if (object.ReferenceEquals(TB.GetType, typeof(StatusStrip))) {
        ((TextBox)TB).ReadOnly = true;
        TB.BackColor = stFromBackColour;
        TB.ForeColor = Color.Gray;
    }
}

答案 2 :(得分:0)

private void AllControlDesign2(ref Control TB)
{
    if (object.ReferenceEquals(TB.GetType, typeof(StatusStrip))) {
        ((TextBox)TB).ReadOnly = true;
        TB.BackColor = stFromBackColour;
        TB.ForeColor = Color.Gray;
    }
}

使用this转换。