Explanation of Solution
Assigning a value to a read-only property:
- Read-only property has a get method, but it does not have any set method to modify the value.
- In order to make a property read only, simply write a “set” accessor method for the property.
- Therefore, the property becomes a read-only property.
- When someone tries to assign a value to a read-only property, an error will occur at the time of executing the program.
Example:
//Include libraries
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
//Define namespace
namespace ConsoleApplication7
{
//Define class
public class Square
{
//Field
private double _perimeter;
//Define a constructor
Square()
{
//Assign value
_perimeter=0.0;
}
//Perimeter property
public double Perimeter
{
//Input value
set
{
_perimeter=value;
}
//Display value
get
{
return _perimeter;
}
;&#x...
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Pearson eText for Starting out with Visual C# -- Instant Access (Pearson+)
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education