static void Main(string[] args) { //int, decimal,float,enum,boolean are value types //burda isler stack memoryde gerceklesiyor int num1 = 10; int num2 = 20; num1 = num2; num2 = 30; Console.WriteLine("Number 1 :" + num1); //what is result? 20 int[] nums1 = new int[] { 1, 2, 3 }; int[] nums2 = new int[] { 10, 20, 30 }; nums1 = nums2; nums2[0] = 1000; Console.WriteLine(nums1[0]); //what is result? if you think that it is same logic as above it would be 10 but it is 1000 // burda isler heap de gerceklesiyor //arays,class,interface .. reference types //new kelimesi heap de alan aciyor ve o alana bir referans degeri(adres) veriyor //burda nums1'in heapteki alani garbage collector tarafindan toplanir. nums1 ve nums2 ayni referansta yer alir Person person1 = new Person(); Person person2 = new Person(); person1.FirstName = "Sercan"; person2 = person1; person1.FirstName = "Hayri"; Console.WriteLine(person2.FirstName);//-->Hayri Customer customer = new Customer(); customer.FirstName = "Ummece"; customer.CreditCardNumber = "12345678"; Employees employees = new Employees(); Person person3 = customer; //person customerin base classi oldugu icin boyle bir atamaya izin veriyor Console.WriteLine(person3.FirstName); //ummece olur //ama creditcardnumbera ulasmak icin sunu yapmam lazim Console.WriteLine(((Customer)person3).CreditCardNumber);//cutomerin credikart nosunu person3'e atamis olduk PersonManager manager = new PersonManager(); manager.Add(person3); manager.Add(customer);//ustteki ile ayni seyi verir }
static void Main(string[] args) { Person person1 = new Person { FirstName = "Samed", LastName = "Muasabasoglu", Id = 1 }; Employee employee1 = new Employee { FirstName = "Ali", LastName = "Soyad", EmployeeId = 165, Id = 2 }; Person person2 = employee1; Console.WriteLine(person2.FirstName); Console.WriteLine(employee1.FirstName); Console.WriteLine(employee1.EmployeeId); Console.WriteLine(((Employee)person2).EmployeeId);//boxing PersonManager personManager = new PersonManager(); personManager.Add(employee1); Console.ReadLine(); }