Эксперементы с md
This commit is contained in:
parent
66a8e1f860
commit
5bc7a2f157
@ -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);
|
||||
|
||||
@ -159,3 +178,19 @@ class Person
|
||||
{
|
||||
public void SayHello() => Console.WriteLine("Hello");
|
||||
}
|
||||
```
|
||||
|
||||
###Структуры
|
||||
|
||||
```
|
||||
struct Person
|
||||
{
|
||||
public string name;
|
||||
public int age;
|
||||
|
||||
public void Print()
|
||||
{
|
||||
Console.WriteLine($"Name: {name} Age: {age}");
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -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}");
|
||||
}
|
||||
}
|
||||
@ -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.
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
de142c11f05cd3451d0fc80307c6b9777eff4cdf53e21bc224e6160abef0828c
|
||||
6f052fbe8164227a52e12a7f78504957cb039892f35f6a997f499e9f58ca1595
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user