static void Main(string[] args) { Apple apple = new Apple("Красное яблоко", 50, 100); Apple apple2 = new Apple("зеленое яблоко", 40, 300); var SummApple = Apple.Add(apple, apple2); var SUmmApple2 = apple + apple2; var SummAppleInt = apple + 600; Console.WriteLine(apple); Console.WriteLine(apple2); Console.WriteLine(SummApple); Console.WriteLine(SUmmApple2); Console.WriteLine(SummAppleInt); Console.ReadLine(); }
static public Apple Add(Apple apple1, int volume) { var apple = new Apple(apple1.Name, apple1.Calorie, volume + apple1.Volume); return(apple); }
public static Apple operator +(Apple apple1, int volume) { return(Apple.Add(apple1, volume)); }
public static Apple operator +(Apple apple1, Apple apple2) { return(Apple.Add(apple1, apple2)); }