class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
class Car { const double MINIMAL_SPEED = 0d; const double MAX_KNOWN_CAR_SPEED = 1229.78d; private double maxSpeed; public double MaxSpeed { get { return maxSpeed; } set { if ( value < MINIMAL_SPEED || value > MAX_KNOWN_CAR_SPEED) throw new ArgumentOutOfRangeException( "MaxSpeed" ); maxSpeed = value ; } } } * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- class car
- {
- // ...
- public static Car CreateRandomCar ()
- {
- return new Car ()
- {
- maxSpeed ​​= ( new Random ()). NextDouble () * double .MaxValue,
- };
- }
- }
* This source code was highlighted with Source Code Highlighter .
- public class HidingProperty <T>
- {
- public delegate T1 Getter <T1> ( ref T1 currentValue);
- public delegate void Setter <T2> ( ref T2 currentValue, T2 newValue);
- private T _storedValue;
- private Getter <T> _getter;
- private Setter <T> _setter;
- public HidingProperty (Getter <T> getter, Setter <T> setter)
- : this ( default (T), getter, setter) {}
- public HidingProperty (T initialValue, Getter <T> getter, Setter <T> setter)
- {
- _storedValue = initialValue;
- _getter = getter;
- _setter = setter;
- }
- public void Set (T newValue)
- {
- _setter ( ref _storedValue, newValue);
- }
- public T Get ()
- {
- return _getter ( ref _storedValue);
- }
- }
* This source code was highlighted with Source Code Highlighter .
- private HidingProperty < double > NewMaxSpeed ​​= new HidingProperty < double > (
- ( ref double currentValue) => { return currentValue; },
- ( ref double currentValue, double newValue) =>
- {
- if (newValue <MINIMAL_SPEED || newValue> MAX_KNOWN_CAR_SPEED)
- throw new ArgumentOutOfRangeException ( "NewMaxSpeed" );
- currentValue = newValue;
- }
- );
* This source code was highlighted with Source Code Highlighter .
- public double Speed
- {
- double speed;
- get { // getter code }
- set { // Setter Code }
- }
Source: https://habr.com/ru/post/116234/
All Articles