Home / C# Programming / Properties :: Discussion

Discussion :: Properties

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

  2. 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;        
               }   
           } 
       }

    View Answer

    Workspace

    Answer : Option A

    Explanation :

    No answer description available for this question.


Be The First To Comment