C# myths about best practices?

Posted by TheMachineCharmer on Stack Overflow See other posts from Stack Overflow or by TheMachineCharmer
Published on 2010-04-12T11:09:26Z Indexed on 2010/04/12 11:13 UTC
Read the original article Hit count: 312

Filed under:
|
|
|

My colleague keeps telling me of the things listed in comments.

I am confused. Can somebody please demystify these things for me?

class Bar
{
    private int _a;

    public int A
    {
        get { return _a; }
        set { _a = value; }
    }

    private Foo _objfoo;

    public Foo OFoo
    {
        get { return _objfoo; }
        set { _objfoo = value; }
    }

    public Bar(int a, Foo foo)
    {
        // this is a bad idea
        A = a;
        OFoo = foo;
    }

    // MYTHS
    private void Method()
    {
        this.A    //1 -
        this._a   //2 - use this when inside the class e.g. if(this._a == 2)
        A         //3 - use this outside the class e.g. barObj.A
        _a        //4 - 
                  // Not using this.xxx creates threading issues.
    }
}
class Foo
{
    // implementation
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about c#2.0