
Hi !
I know I’m late to the party here, however I’m still enjoying some of the new C# 9 features a lot. I just realized that now, I can create objects in a different way, which is still super clear to read.
Disclaimer: some of the new features are cool, however my gut told me that they will make code harder to read. I also understand that I have 20 years of writing C# code in my back, so I need to find the balance here.
As usual, 2 lines of code are the best way to showcase this:
// old school
var pointOldSchool = new System.Drawing.Point(3, 5);
// new school and still very readable
System.Drawing.Point pointCSharpNine = new(3, 5);
// crappy output
Console.WriteLine("Old School: var pointOldSchool = new System.Drawing.Point(3, 5);");
Console.WriteLine(pointOldSchool);
Console.WriteLine("C#9: System.Drawing.Point pointCSharpNine = new(3, 5);");
Console.WriteLine(pointCSharpNine);
This this output as expected:
Old School: var pointOldSchool = new System.Drawing.Point(3, 5);
{X=3,Y=5}
C#9: System.Drawing.Point pointCSharpNine = new(3, 5);
{X=3,Y=5}
I like this new one ๐
References
ยฟCon ganas de ponerte al dรญa?
En Lemoncode te ofrecemos formaciรณn online impartida por profesionales que se baten el cobre en consultorรญa:
- Si tienes ganas de ponerte al dรญa con Front End (ES6, Typescript, React, Angular, Vuejs…) te recomendamos nuestros Mรกster Front End: https://lemoncode.net/master-frontend#inicio-banner
- Si te quieres poner al dรญa en Backend (stacks .net y nodejs), te aconsejamos nuestro Bootcamp Backend: https://lemoncode.net/bootcamp-backend#bootcamp-backend/banner
- Y si tienes ganas de meterte con Docker, Kubernetes, CI/CD…, tenemos nuestro Bootcamp Devops: https://lemoncode.net/bootcamp-devops#bootcamp-devops/inicio