static void Main(string[] args) { // Error! Cannot directly access private members // from an object! //emp.empName = "Marv"; Console.WriteLine("***** Fun with Encapsulation *****\n"); Employee emp = new Employee("Marvin", 456, 30000); emp.GiveBonus(1000); emp.DisplayStats(); // Use the get/set methods to interact with the object's name. emp.SetName("Marv"); Console.WriteLine("Employee is named: {0}", emp.GetName()); // Longer than 15 characters! Error will print to console. Employee emp2 = new Employee(); emp2.SetName("Xena the warrior princess"); // Reset and then get the Name property. emp.Name = "Marv"; Console.WriteLine("Employee is named: {0}", emp.Name); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Encapsulation *****\n"); Employee emp = new Employee("Marvin", 456, 30000); emp.GiveBonus(1000); emp.DisplayStats(); emp.Name = "Marv"; Console.WriteLine("Employee is named: {0}", emp.GetName()); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("***** Fun with Encapsulation***\n"); Employee emp = new Employee("Marvin", 456, 30000); emp.GiveBonus(1000); emp.DisplayStats(); // Использовать методы get/set для взаимодействия с именем обьекта emp.SetName("Marv"); Console.WriteLine("Employee is named: {0}", emp.GetName()); Console.ReadLine(); }
static void Main(string[] args) { Employee emp = new Employee("Marvin", 456, 30000); emp.GiveBonus(1000); emp.DisplayStats(); // Use the get/set methods to interact with the object's name. emp.SetName("Marv"); Console.WriteLine("Employee is named: {0}", emp.GetName()); Console.ReadLine(); }
static void Main(string[] args) { //Теперь все в порядке; Console.WriteLine("***** Fun with Encapsulation *****\n"); Employee emp = new Employee("Marvin", 456, 30000); emp.GiveBonus(1000); emp.DisplayStatus(); //Использование get/set для взаимодействия с именами объектов; emp.SetName("Marv"); Console.WriteLine("Employee is named: {0}", emp.GetName()); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("**** Fun with Encapsulation ****\n"); Employee emp = new Employee("Marvin", 456, 30000); emp.GiveBonus(1000); emp.DisplayStats(); // Использовать методы get/set ждя взаимодействия с именем обьекта. emp.SetName("Marv"); Console.WriteLine("Employee is named: {0} ", emp.GetName()); Console.ReadLine(); // Создаем joe Employee joe = new Employee(); joe.Age++; // Упращенние записи "joe.setAge(joe.GetAge() + 1;" Console.ReadLine(); }
private static void Main(string[] args) { Console.WriteLine("***** Fun with Encapsulation ****\n"); var emp = new Employee("Marvin", 456, 30000, 20); emp.GiveBonus(1000); emp.DisplayStats(); emp.Name = "Marv"; Console.WriteLine("Employee is named: {0}", emp.GetName()); var emp2 = new Employee(); emp2.SetName("Xena the warrior princess"); var joe = new Employee(); joe.Age++; Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("*** Fun with Encapsulation ***"); Employee emp = new Employee("Jake", 30, 30000); emp.GiveBonus(1000); emp.Display(); emp.SetName("Mike"); Console.WriteLine("Employee is named: {0}", emp.GetName()); Employee emp2 = new Employee(); emp2.Name = "Xena"; Console.WriteLine("Name of Employee: {0}", emp2.Name); Employee joe = new Employee(); joe.Age++; joe.Display(); Console.ReadLine(); }