Learn about pattern matching in C#

💡𝗖# 𝗧𝗶𝗽 ✔𝗥𝗲𝗹𝗮𝘁𝗶𝗼𝗻𝗮𝗹 𝗣𝗮𝘁𝘁𝗲𝗿𝗻𝘀 𝗠𝗮𝘁𝗰𝗵𝗶𝗻𝗴 ✅ 𝗥𝗲𝗹𝗮𝘁𝗶𝗼𝗻𝗮𝗹 𝗣𝗮𝘁𝘁𝗲𝗿𝗻𝘀 𝗠𝗮𝘁𝗰𝗵𝗶𝗻𝗴 is a feature introduced in 𝗖# 𝟵 that enhances the pattern matching capabilities of the language. Pattern matching is a way to compare values against patterns. ✅ It is a 𝗳𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝗮𝗹 programming technique, which means that it focuses on the evaluation of expressions rather than the control flow of your code. 🔥  𝗔𝗱𝘃𝗮𝗻𝘁𝗮𝗴𝗲𝘀 𝗼𝗳 𝗿𝗲𝗹𝗮𝘁𝗶𝗼𝗻𝗮𝗹 𝗽𝗮𝘁𝘁𝗲𝗿𝗻𝘀 𝗺𝗮𝘁𝗰𝗵𝗶𝗻𝗴: ◾ 𝗖𝗼𝗻𝗰𝗶𝘀𝗲𝗻𝗲𝘀𝘀: Relational patterns matching can be used to create more concise and readable code. ◾ 𝗘𝘅𝗽𝗿𝗲𝘀𝘀𝗶𝘃𝗲𝗻𝗲𝘀𝘀: Relational patterns matching can be used to express more complex conditions. 🤔 Which one do you prefer? 𝗧𝗵𝗮𝗻𝗸 𝘆𝗼𝘂 𝗳𝗼𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 📖 #csharp #dotnet #programming #aspnetcore #programmingtips

  • 𝗥𝗲𝗹𝗮𝘁𝗶𝗼𝗻𝗮𝗹 𝗣𝗮𝘁𝘁𝗲𝗿𝗻𝘀 𝗠𝗮𝘁𝗰𝗵𝗶𝗻𝗴

𝗔𝗻𝗼𝘁𝗵𝗲𝗿 𝗲𝘅𝗮𝗺𝗽𝗹𝗲 𝘂𝘀𝗶𝗻𝗴 "𝗼𝗿"

  • No alternative text description for this image

𝗔𝗻 𝗲𝘅𝗮𝗺𝗽𝗹𝗲 𝘂𝘀𝗶𝗻𝗴 "𝗮𝗻𝗱"

  • No alternative text description for this image
Matheus Brito

Software Engineer | .NET, Java, Angular, React | SaaS & Cloud Solutions (Azure/AWS)

10mo

Good information, I'll save that forever!

Raman Chakhouski

Senior Engine Programmer at People Can Fly

10mo

more syntactic sugar

Maggie Veen

Junior Software Engineer

10mo

Can you provide an example of relational pattern matching using a switch statement?

Mattia Collalti

💈 Senior Software Developer | 👾 Front: Angular, React.js | ☎️ Mobile: Xamarin, Ionic | 🤖 Back: Express.js, .NET Core | 🗄️ DB: MongoDb, MySQL | 🫀Tech Lead & DevOps: Jira, Docker, AWS, Gitlab, Github, Ionic Appflow

10mo

C# is one of the most beautiful languages syntactically that I have ever seen.

Elliot One

AI SaaS Engineer | Founder @ XANT & Monoversity | Entrepreneur

10mo

This is a good example, Jalal. The new approach to pattern matching while having multiple conditions, using relation patterns, is the new idiomatic approach in C#. It's good to be familiar with the "and", "is", and "or" keywords in C#.

Mike van Kuik

I ensure that your Functional Management team experiences more peace and focus, through clear documentation and transparent processes.

10mo

Even though I can read both statements both find, the later is more "English" which makes it easier, not just for me but also if I need to explain it to someone who's less knowledgeable about programming.

Amir Eslamzadeh

.Net BackEnd Programmer | API | Microservicess

10mo

Insightful! I mostly use Relational pattern, it's most readable

MATTHEW O. LORENTZ

SENIOR SOFTWARE ENGINEER

10mo

Love this

See more comments

To view or add a comment, sign in

Explore topics