class Program { static void Main(string[] args) { Encapsulation encapsulate = new Encapsulation(); encapsulate.Mark = 1; encapsulate.Display(); encapsulate.Mark = 20; encapsulate.Display(); Console.ReadKey(); } } public class Encapsulation { private int _mark; public int Mark { get { return _mark; } set { if (_mark < 5) _mark = 0; else _mark = value; } } public void Display() { Console.WriteLine("Mark: " + Mark); } }
if (_mark < 5)
if (value < 5)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)