## Классы
```cs
namespace Lesson1;

public class Pen {

}
```
  
```cs
namespace CSharpHelp2024;

public class Tools {
	public Tools() {
	
	}
	
	public static void Foo() {
	
	}
}

using CSharpHelp2024.Classes;
using CsharpHelp2024;
using static CSharpHelp2024.Tools;
using D = CSharpHelp2024.Classes.A;
using E = CSharpHelp2024.A;

B a = new();
var b = 10;
a.Foo(a:ref b, in b, c:out b);
Console.WriteLine(b);
Foo();

var c = new CSharpHelp2024.Classes.A();
var d = new D();
var e = new E();
```
## Свойства
```cs
namespace Lesson1;

public class Pen
{
	public int Size { get; set; }
	
	private float _weight { get; set; }
	
	public void Draw(int size = 1)
	{
		Size -= size;
	}
	
	public float Weight
	    {
	        get
	        {
	            return _weight;
	        }
	        set
	        {
	            _weight = value;
	        }
	    }
}
```
  
```cs
public class B {
	private int[] _a;
	protected int[] b;
	public 
	
	public B() {
	
	}
	
	public void Foo(ref int a, in int b, out int c) {
		c = b;
		a = a + 1;
	} 
}
```
## Поля и методы класса
```cs
namespace Lesson1;

public class Pen
{
    private int _size;

    public int get_Size()
    {
        return _size;
    }

    public void set_Size(int size)
    {
        _size = size;
    }

    public void Draw(int size = 1)
    {
        _size -= size;
    }
}
```
  
```cs
namespace CSharpHelp2024;

public class A {
	private int _id;
	private int _i;
	
	public A() {
		LastName = "";
	}
	
	public int get_Id() {
		return _id;
	}
	
	public void set_Id(int id) {
		_id = id;
	}
	
	public int Id {
		get;
		set;
	}
	
	public int Name {
		get;
	}
	
	public int LastName {
		get;
		private set;
	}
	
	public int I {
		get => _i;
		set => _i = value;
	}
}
```
## Конструкторы класса
```cs
public class Pen
{
    public int Size { get; set; }
    
    public Pen()
    {
        Size = 100;
    }
	
    public Pen(int size)
    {
        Size = size;
    }
	
    public Pen(Pen pen)
    {
        Size = pen.Size;
    }
}
```

```cs
namespace CSharpHelp2024;

public class C : IDisposable {
	
	public int _array[];
	private readonly Stream _stream;
	
	public C(int i, params string[] args, params int[] args2) {
		_array = new int[i];
		_stream = new FilesTream(path:"1.txt", FileMode.OpenOrCreate, FileAccess.Write);
		for (int j = 0; j < args.Length; j++) {
			Console.WriteLine(args[j])
		}
		foreach (var t:string int args) {
			vare bytes:byte[];
			Console.WriteLine(t);
		}
	}
	
	public void D() {
		C c = new C(i:10);
	}
	
	public void D(int j = 10, int i = 10) {
		
	}
	
	~C() {
		_array = null;
	}
	
	public void Dispose() {
		throw new NotImplementedException();
		// освобождаем внешние ресурсы
	}
}

using var f = new C(i:10, params args: "Hello", " ", "World", "!");
f.D();
f.D(j:10, i:15);
```
## Наследование
```cs
public abstract class Pen
{
    public int Size { get; set; }
    private int _weight = 0;
    protected float Price = 10;
}

public sealed class Pen2 : Pen
{
    public Pen2()
    {
        Size = 10;
        Price = 20;
        _weight = 0; // Ошибка
    }
}
```
  
```cs
namespace CSharpHelp2024;
public class D : C

public D(int i, params string[] args) : {

}

public D() : base(1, "Hello", " ", "World", "!");

public class E : D {
	public E(int i) : base(i:1, params arg "@") {
		
	}
}
```
## Абстрактные классы
```cs
public abstract class Pen
{
    public int Size { get; set; }
        
    public abstract int Draw();
}

public class Pen2 : Pen
{
    public override int Draw()
    {
        return Size--;
    }
}
```

```cs
public abstract class E {
	protected string _name;
	protected string _lastName;
	protected E(string LastName, string name) {
		Name = name;
		LastName = lastName;
	}
	public abstract string Name {
		get;
		set;
	}
	public abstract string LastName {
		get;
		set;
	}
	public abstract string FullName();
}

public sealed class F : E {
	public int Age;
	public F(string lastName, string name) : base(lastName) {
		
	}
	
	protected override string Name => "_name";
	protected override string LastName => "_lastName";
	protected override string FullName() => "{_name} {}"
	
	public new void Foo() {
	Console.WriteLine(FullName());
	}
}

using var f2 = new D(10, "Hello", " ", "ПИ");
Object f3 = newF(ElastName: "Hello", name: "World");

var f4 = (F)f3;
var f5 = (F)f4;
if (f3 is F f5) {
	Console.WriteLine(f5.Name);
}

var f6 = f3 as F;
if (f6 is {}) {
	Console.WriteLine(f6.LastName);
	f5.Foo();
}

Lesson1();
Lesson2();

static void Lesson1() {
	string a = "Hello";
	string b = "Hello";
	string c = default;
	a = a + b;
	var now:DataTime = DataTime.Now;
	
	void Bar(string s) {
	
	}
	
	var sb = new StringBuilder();
	for (int i = 0; i < 1_000_000; i++) {
		c += i.ToString();
		sb.Append(i);
	}
	Console.WriteLine((DataTime.Now - now));
	
	if (a == b) {
		unsafe {
			Console.WriteLine(*a);
		}
	}
}
static void Lesson2() {

}
```
## Виртуальные методы
```cs
public class Pen
{
    public int Size { get; set; }

    public virtual int Draw()
    {
        return Size--;
    }
}

public class Pen2 : Pen
{
    public override int Draw()
    {
        return Size--;
    }
}
```
## Скрытие
```cs
public class Pen
{
    public int Size { get; set; }

    public int Draw()
    {
        return Size--;
    }
}

public class Pen2 : Pen
{
    public new int Draw()
    {
        return Size -= 2;
    }
}

```
## Конструкторы при наследовании
```cs
public class Pen
{
    public int Size { get; set; }

    public Pen(int size)
    {
        Size = size;
    }
}

public class Pen2 : Pen
{
    public Pen2() : base(100)
    {
        
    }
}
```
## `base` и `this`
```cs
public class Pen
{
    public int Size { get; set; }
}

public class Pen2 : Pen
{
    public new int Size { get; set; }

    public void Draw()
    {
        this.Size--;
        base.Size--;
    }
}
```
## Инициализация объектов класса
```cs
class Program
{
    public static void Main(string[] args)
    {
        var p = new Pen();
        p.Size = 100;
        var p1 = new Pen{ Size = 100 };
    }
}
```
## Перечисления
```cs
namespace CSharpHelp2024.Enums;

public enum DayOfWeek : byte {
	Sunday = 7,
	Monday = 1,
	Tuesday = 2,
	Wednesday = 3,
	Thursday = 4,
	Friday = 5,
	Saturday = 6
}
```
## Обобщения
```cpp
public class Pen<T>
{
    public T Size { get; set; }
	
    public virtual T Set<TD>(TD something)
    {
        if (something is T size)
        {
            Size = size;
        }
		
        return Size;
    }
}
```
  
```cpp
public class Pencil : Pen<int>
{
    public override int Set<TD>(TD something)
    {
        return something is int 
            ? Size 
            : 0;
    }
}

public class Pencil<T> : Pen<T>
{
    public override T Set<TD>(TD something)
    {
        return (something is T s
            ? Size = s
            : default)!;
    }
}
```
  
```cpp
public class G<TD> {
	public void Bar(TD par) {
		par.Bar();
	}
	
	public TD Foo() {
		return default;
	}
	
	public void Foo<T>(T par) {
		Console.WriteLine("Hello, World!");
	}
}

static void Lesson3() {
	A t = new();
	var t = new G<A>();
	t.Bar(a);
	t.Bar(10.0); 
	t.Foo(10);
	t.Foo("");
	t.Foo(t);
	var t2 = new H();
	t2.Bar(a);
}
```
## Интерфейсы
```cpp
public interface IPen
{
    int Size { get; set; }
    void Draw();
}

public class Pen : IPen
{
    public int Size { get; set; }
    public void Draw()
    {
        Size--;
    }
}
```
  
```cpp
public interface IA {
	void Bar();
}

public class A : IA {
	IA a = new A();
	var t = new G<IA>;
}

void IA.Bar() {

}

public class G<TD, TI> 
	where TD : class, IA, new()
	where TI : struct, IA
{

}

public class H<TD> : G<TD> 
	where TD : class, IA
{
	
}
```
## Множественная реализация интерфейсов
```cpp
public interface IPen
{
    int Size { get; set; }
}

public interface ITool
{
    void Draw();
}

public class Pen : IPen, ITool
{
    public int Size { get; set; }

    public void Draw()
    {
        Size--;
    }
}
```
  
```cpp
internal interface IJ {
	public void Foo();
}

internal interface IK {
	public void Bar();
}

internal class L : J, JK {
	public void Bar() {
		throw new NotInplementedException();
	}
	
	public new void Foo() {
		Console.Writeline("Class L");
	}
}

var l = new L();
IJ ij = l;
IK ik = l;
l.Foo();
```
  
```cpp
public interface IWriter<T> {
	void Write(T value)
}

public interface IReader<T> {
	T Read();
}

public interface IData {
	string Data { get; set; }
}

public class ConsoleWriter : IWriter<IData> {
	public void Write(IData value) {
		Console.WriteLine(value.ToString());
	}
}

internal class NewConsoleWriter : IWriter<Data2> {
	public void Write(IData value) {
		Console.WriteLine(value.Data);
	}
}

public class ConsoleReader : IReader<IData> {
	public Data2 Read() {
		_data = data;
	}
}

public class ConsoleReader(Data2 _data) : IReader<IData> {
	return _data;
}

internal class Data1 : IData {
	public string Data { get; set; }
}

public class Data2 : IData {
	
}

Data1 a4 = new() {
	Data = "Hello world!";
};
Data1 a5 = new() {
	Data = "Hello world!";
};
IWriter<IData> writer1 = new ConsoleWriter();
IWriter<Data1> writer11 = writer1;
writer11.Write(a4);
writer1.Write(a4);
IWriter<Data1> writer2 = new NewConsoleWriter();
IWriter<Data2> writer3 = writer2;
writer2.Write(a5);
writer3.Write(a5);

IReader<Data2> reader = new ConsoleReader(a5);
Console.WriteLine(reader.Read().Data);
```