Friday, 16 December 2011

85.Which of the following is the correct way to implement a read only property Length in aSample class?

A.class Sample
{
    int len;
    public int Length
    {
        get
        {
            return len;
        }
    }
}
B.class Sample
{
    public int Length
    {
        get
        {
            return Length;
        }
    }
}
C.class Sample
{
    int len;
    public int Length
    {
        get
        {
            return len;
        }
        set
        {
            len = value;
        }
    }
}
D.class Sample
{
    int len;
    public int Length
    {
        Readonly get
        {
            return len;
        }
    }
}
Answer: Option A