diff --git a/CSHARP/Lessons.md b/CSHARP/Lessons.md index c731da7..e03491d 100644 --- a/CSHARP/Lessons.md +++ b/CSHARP/Lessons.md @@ -1,5 +1,6 @@ -=== Классы и объекты === +###Классы и объекты +``` Person tom = new Person(); string personName = tom.name; int personAge = tom.age; @@ -19,9 +20,11 @@ class Person Console.WriteLine($"Имя: {name} Возраст: {age}"); } } +``` -=== Конструкторы, инициализаторы и деконструкторы === +###Конструкторы, инициализаторы и деконструкторы +``` Person tom = new Person(); Person bob = new Person("Bob"); Person sam = new Person("Sam", 25); @@ -47,8 +50,8 @@ class Person } } - - +``` +``` Person sam = new Person("Sam", 25); sam.Print(); @@ -72,8 +75,11 @@ class Person Console.WriteLine($"name: {name} age: {age}"); } } +``` -"Цепочка вызова конструкторов" +###Цепочка вызова конструкторов + +``` Person sam = new Person("Sam", 25); sam.Print(); @@ -90,8 +96,11 @@ class Person } public void Print() => Console.WriteLine($"Name: {name} Age: {age}"); } +``` -"Первичные конструкторы" +###Первичные конструкторы + +``` var tom = new Person("Tom", 38); Console.WriteLine(tom); @@ -100,7 +109,11 @@ public class Person(string name, int age) public Person(string name) : this(name, 18) { } public void Print() => Console.WriteLine($"name: {name}, age: {age}"); } -"Инициализаторы объектов" +``` + +###Инициализаторы объектов + +``` Person tom = new Person { name = "Tom", company = { title = "Microsoft" } }; tom.Print(); @@ -120,8 +133,11 @@ class Company { public string title = "Unknown"; } +``` -"Деконструкторы" +###Деконструкторы + +``` Person person = new Person("Tom", 33); (string name, int age) = person; //(_, int age) = person если нужен только возраст Console.WriteLine(name); @@ -142,8 +158,11 @@ class Person personAge = age; } } +``` -"Класс Program и метод Main. Программы верхнего уровня" +###Класс Program и метод Main. Программы верхнего уровня + +``` string hello = "Hello"; Print(hello); @@ -158,4 +177,20 @@ tom.SayHello(); class Person { public void SayHello() => Console.WriteLine("Hello"); -} \ No newline at end of file +} +``` + +###Структуры + +``` +struct Person +{ + public string name; + public int age; + + public void Print() + { + Console.WriteLine($"Name: {name} Age: {age}"); + } +} +``` \ No newline at end of file diff --git a/CSHARP/Program.cs b/CSHARP/Program.cs index da868bb..bfe9241 100644 --- a/CSHARP/Program.cs +++ b/CSHARP/Program.cs @@ -1,7 +1,10 @@ -Person tom = new(); -tom.SayHello(); - -class Person +struct Person { - public void SayHello() => Console.WriteLine("Hello"); + public string name; + public int age; + + public void Print() + { + Console.WriteLine($"Name: {name} Age: {age}"); + } } \ No newline at end of file diff --git a/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfo.cs b/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfo.cs index e20c5b1..2c0d6b7 100644 --- a/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfo.cs +++ b/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfo.cs @@ -13,10 +13,10 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("CSHARP")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+837beff6c4cc7361396562a13cbbd8cb10871924")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+66a8e1f86075a7e1275eedad85bc41a5fc0e81c6")] [assembly: System.Reflection.AssemblyProductAttribute("CSHARP")] [assembly: System.Reflection.AssemblyTitleAttribute("CSHARP")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Создано классом WriteCodeFragment MSBuild. +// Generated by the MSBuild WriteCodeFragment class. diff --git a/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache b/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache index 2e51eb7..d644290 100644 --- a/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache +++ b/CSHARP/obj/Debug/net9.0/CSHARP.AssemblyInfoInputs.cache @@ -1 +1 @@ -de142c11f05cd3451d0fc80307c6b9777eff4cdf53e21bc224e6160abef0828c +6f052fbe8164227a52e12a7f78504957cb039892f35f6a997f499e9f58ca1595