CSHARP_1001_NOTES Telegram 768
🔥 Лучшая фича C# за последние годы? Pattern Matching

Зачем он нужен:
Pattern matching позволяет элегантно проверять объект на определённые свойства:

- Является null или не null
- Является объектом конкретного типа
- Имеет свойство с определённым значением

В связке со switch-выражениями и record-типами это превращает код в лаконичный и выразительный.

📌 Пример:

static string PrintShape(object shape) =>
shape switch
{
null => "Нет объекта",
Circle c => $"Круг с радиусом {c.Radius}",
Rectangle { Width: > 0, Height: > 0 } r => $"Прямоугольник {r.Width}x{r.Height}",
_ => "Неизвестная фигура"
};



tgoop.com/csharp_1001_notes/768
Create:
Last Update:

🔥 Лучшая фича C# за последние годы? Pattern Matching

Зачем он нужен:
Pattern matching позволяет элегантно проверять объект на определённые свойства:

- Является null или не null
- Является объектом конкретного типа
- Имеет свойство с определённым значением

В связке со switch-выражениями и record-типами это превращает код в лаконичный и выразительный.

📌 Пример:


static string PrintShape(object shape) =>
shape switch
{
null => "Нет объекта",
Circle c => $"Круг с радиусом {c.Radius}",
Rectangle { Width: > 0, Height: > 0 } r => $"Прямоугольник {r.Width}x{r.Height}",
_ => "Неизвестная фигура"
};

BY C# 1001 notes




Share with your friend now:
tgoop.com/csharp_1001_notes/768

View MORE
Open in Telegram


Telegram News

Date: |

Done! Now you’re the proud owner of a Telegram channel. The next step is to set up and customize your channel. How to create a business channel on Telegram? (Tutorial) The initiatives announced by Perekopsky include monitoring the content in groups. According to the executive, posts identified as lacking context or as containing false information will be flagged as a potential source of disinformation. The content is then forwarded to Telegram's fact-checking channels for analysis and subsequent publication of verified information. Developing social channels based on exchanging a single message isn’t exactly new, of course. Back in 2014, the “Yo” app was launched with the sole purpose of enabling users to send each other the greeting “Yo.” As the broader market downturn continues, yelling online has become the crypto trader’s latest coping mechanism after the rise of Goblintown Ethereum NFTs at the end of May and beginning of June, where holders made incoherent groaning sounds and role-played as urine-loving goblin creatures in late-night Twitter Spaces.
from us


Telegram C# 1001 notes
FROM American