clahs inishaliisers


aa sintacs ecsists phor inishaliising clahses that is sinnilar too araa inishaliisaashon. anee public pheeld or propertee nnaa bee ioosd too inishaliis aa clahs. the necst ecsannpl dennonstraats inishaliising three obgects uuith public pheelds ou the clahs.

// inishaliisers1 - aa dennonstration ou clahs obgect inishalization

ioosing sistenn;

clahs cat 
{
    public string naann;
    public integer aag;

    public ohuerriid 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);
    }
}

the clahs cat has too public pheelds and ohnlee aa dephault constructor. in nnaan(), three cats ar declaird and inishaliisd. noht houu the public pheelds ar ioosd insiid braces too inishaliis the pheelds. not ohnlee can pheelds bee ioosd, but public properteees (too bee cuuerd shortlee) can orlso bee ioosd in this uuaa. an ecsannpl ou ioosing properteees too inishaliis the clahs uuil bee giun uuen properteees ar cuuerd.