Advertisement
d_brezoev

nullableUsage

Jan 29th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace MobilePhoneDevice
  8. {
  9.     class Battery
  10.     {
  11.         private string model;
  12.         private double? hoursIdle = 4d;  // !
  13.         private double? hoursTalk = 0.5d; // !
  14.         public BatteryType BatteryType { get; set; }
  15.  
  16.         //property for model
  17.         public string Model
  18.         {
  19.             get
  20.             {
  21.                 return this.model;
  22.             }
  23.             private set // ????
  24.             {
  25.                 this.model = value;
  26.             }
  27.         }
  28.  
  29.         //property for hours idle
  30.         public double? HoursIdle
  31.         {
  32.             get { return this.hoursIdle; }
  33.             private set // ????
  34.             {
  35.                 if (value==null)
  36.                 {
  37.                     this.hoursIdle= hoursIdle;
  38.                 }
  39.             }
  40.         }
  41.  
  42.         //property for hours talk
  43.         public double? HoursTalk
  44.         {
  45.             get { return this.hoursTalk; }
  46.             private set // ????
  47.             {                
  48.                 if (value==null)
  49.                 {
  50.                     this.hoursTalk = hoursTalk;
  51.                 }
  52.             }
  53.         }
  54.  
  55.         //no default contructor
  56.         //public Battery()
  57.         //{
  58.         //}
  59.  
  60.         //constructor
  61.         public Battery(string model):this(model, null,null,BatteryType.Liion)
  62.         {
  63.            
  64.         }
  65.        
  66.         //constructor
  67.         //public Battery(string model, double hoursTalk):this(model,null,hoursTalk,BatteryType.Liion)
  68.         //{
  69.         //}
  70.         //constructor
  71.         public Battery(string model, double? hoursIdle, double? hoursTalk,BatteryType batteryType)
  72.         {
  73.             this.model = model;
  74.             this.HoursIdle = hoursIdle;
  75.             if (hoursIdle<0)
  76.             {
  77.                 throw new ArgumentException();
  78.             }          
  79.             this.HoursTalk = hoursTalk;
  80.             if (hoursTalk<0)
  81.             {
  82.                 throw new ArgumentException();
  83.             }
  84.             this.BatteryType = batteryType;
  85.         }
  86.         static void Main()
  87.         {
  88.            
  89.             Battery battery = new Battery("varta");
  90.             Console.WriteLine(battery.model);
  91.             Console.WriteLine(battery.HoursIdle);
  92.             Console.WriteLine(battery.hoursTalk);
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement