Properties

Q1: Which of the following is the correct way to implement a read only property Length in a Sample class?

A
class Sample
{
    int len;
    public int Length
    {
        get
        {
            return len;
        } 
    } 
}

B
class Sample
{
    public int Length
    {
        get
        {
            return Length;
        } 
    } 
}

C
class Sample
{
    public int Length
    {
        get
        {
            return Length;
        } 
    } 
}

D
class Sample
{
    int len;
    public int Length
    {
        Readonly get
        {
            return len;
        } 
    } 
}

ANS:A -

class Sample
{
    int len;
    public int Length
    {
        get
        {
            return len;
        } 
    } 
}

No answer description is available. Let's discuss.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.