<pre>class Counter { int val; public int Value { get { return val; } set { val = value; InRange(); } } int min { get; } int max { get; } public Counter(int _val, int _min, int _max) { Value = _val; min = _min; max = _max; } public Counter(int _min, int _max) { min = _min; max = _max; Value = new Random().Next(min, max + 1); } public static Counter operator ++(Counter c) { c.Value++; return c; } public static Counter operator --(Counter c) { c.Value--; return c; } void InRange() { if (val > max || val < min) ; throw new ArgumentOutOfRangeException("Значение не в заявленном диапазоне."); } class Class1 { static void Main() { Counter counter = new Counter(5, 0, 10); Counter counterRand = new Counter(7, 29); counter++; counterRand--; } } } }
Class1
Counter
public Counter(int _val, int _min, int _max) { min = _min; max = _max; Value = _val; }
Value
InRange()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)