Home / C# Programming / Properties :: Discussion

Discussion :: Properties

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

  2. A.
     class Sample
     {   
         public int Length  
         {        
             set       
             {           
                Length = value;    
             }      
          } 
       }
    
    B.
      class Sample
      {  
         int len;  
         public int Length 
         {        
             get     
             {           
                 return len;     
             }       
             set        
             {        
                   len = value;   
              }     
           }   
        } 
    
    C.
     class Sample
     {   
        int len;   
        public int Length    
        {         
            WriteOnly set      
            {            
                len = value;      
            }      
         }  
      }
    
    D.
     class Sample
     {  
         int len;  
         public int Length   
         {       
             set    
             {          
                 len = value;     
             }     
         } 
      }
    

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    No answer description available for this question.


Be The First To Comment