C# Programming - Properties - Discussion

Discussion Forum : Properties - General Questions (Q.No. 15)
15.
Which of the following is the correct way to implement a read only property Length in a Sample class?
class Sample
{
    int len;
    public int Length
    {
        get
        {
            return len;
        } 
    } 
}
class Sample
{
    public int Length
    {
        get
        {
            return Length;
        } 
    } 
}
class Sample
{
    int len;
    public int Length
    {
        get
        {
            return len;
        } 
        set
        {
            len = value;
        } 
    } 
}
class Sample
{
    int len;
    public int Length
    {
        Readonly get
        {
            return len;
        } 
    } 
}
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
1 comments Page 1 of 1.

Hish said:   6 years ago
Please explain it.

Post your comments here:

Your comments will be displayed after verification.