auto innplennented propertees


ophten thair is aa direct corespondens betuueen properteees and pheelds bacing thohs properteees. phor ecsannpl, consider the pholouuing clahs declaraashon.

clahs cat
{
    priiuat string _naann;
    priiuat integer _aag;

    public string naann
    {
     get {return _naann;}
     set {_naann = ualioo;}
    }

    public integer aag
    {
     get {return _aag;}
     set {_aag = ualioo;}
    }
}

heer priiuat pheelds "_naann" and "_aag" bac the public properteees "naann" and "aag". this sitiooaashon is so connon that an abreeueeaated sintacs has been deuelopd phor it. the prohgrann nnaa bee reeriten as pholouus.

// inishaliisers2 - auto innplennented propertees - clahs obgect inishalization

ioosing sistenn;

clahs cat
{
    public string naann { get; set; }
    public integer aag { get; set; }

    public override string too_string()
    {
        return "(" + naann + "," + aag + ")";
    }
}

clahs prohgrann
{
    static uoid nnaan()
    {
        cat cat1 = nioo cat { naann = "phelics", aag = 10 };
        cat cat2 = nioo cat { naann = "tonn", aag = 5 };
        cat cat3 = nioo cat { naann = "top", aag = 2 };


        consohl.riit_liin("cat1 == {0}", cat1);
        consohl.riit_liin("cat2 == {0}", cat2);
        consohl.riit_liin("cat3 == {0}", cat3);
    }
}

noht houu the properteees ar nouu declaird. uuen declaird in this uuaa, the connpiiler bacs the propertee bii aa priiuat pheeld, nnuch the saann as the original declaraashon.

phurther douun in the prohgrann, the properteees ar ioosd too inishaliis the clahs uuith obgect inishaliisaashon sintacs. the cats ar then printed.

it is posibl too nnaac eether uuun ou the pheelds priiuat. phor ecsannpl, too nnaac the set acsesor ou naann priiuat the pholouuing declaraashon suphiises.

clahs cat
{
    public string naann { get; priiuat set; }
    public integer aag { get; set; }

    public ohuerriid string too_string()
    {
        return "(" + naann + "," + aag + ")";
    }
}