static void RemoveLongestCall(Gsm gsm) { Call[] calls = gsm.CallHistory.ToArray(); Array.Sort(calls, (x, y) => x.Duration.CompareTo(y.Duration)); // Using lamda expresion in order to sort the array gsm.CallHistory = calls.ToList(); gsm.CallHistory.RemoveAt(gsm.CallHistory.Count - 1); }
static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR"); Console.OutputEncoding = Encoding.UTF8; Gsm gsm = new Gsm("N95", "Nokia"); gsm.AddCall(DateTime.Now, "0883442233", 30); gsm.AddCall(DateTime.Now, "0883442233", 30); gsm.AddCall(DateTime.Now, "0883442233", 30); gsm.AddCall(DateTime.Now, "0883442233", 60); gsm.AddCall(DateTime.Now, "0883442233", 30); gsm.AddCall(DateTime.Now, "0883442233", 30); foreach (var call in gsm.CallHistory) { Console.WriteLine("Date:{0}\nTime:{1}\nPhone Number:{2}\nDuration:{3}s\n", call.CallDate, call.CallTime, call.DialedNumber, call.Duration); } Console.WriteLine(gsm.GetTotalPrice(0.37M)); RemoveLongestCall(gsm); Console.WriteLine(gsm.GetTotalPrice(0.37M)); Console.WriteLine(); foreach (var call in gsm.CallHistory) { Console.WriteLine("Date:{0}\nTime:{1}\nPhone Number:{2}\nDuration:{3}s\n", call.CallDate, call.CallTime, call.DialedNumber, call.Duration); } gsm.ClearCallHistory(); }
static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; try { Gsm[] devices = new Gsm[3] { new Gsm("Galaxy Note 3", "Samsung"), new Gsm("iPhone", "Apple", 1000), new Gsm("N95", "Nokia", 300, "Bai Pesho", "BP-4L", BatteryType.LiIon, 6, 400) }; foreach (Gsm device in devices) { Console.WriteLine(device); } } catch (Exception e) { Console.WriteLine("Cannot create Gsm object!" + e.Message); } }
// Constructors public GsmTest(Gsm[] devices) { this.Devices = devices; }
// Constructors static Gsm() { IPhone4S = new Gsm("iPhone 4S", "Apple"); }