James Montemagno
James Montemagno

Live, Love, Bike, and Code.

Tags


James Montemagno

C#

Enabling C# 9 in Xamarin & .NET Standard Projects

Whoa! .NET 5 is out and C# 9 is out! This means you are ready to use records, new pattern matching, and more! But wait a second... your apps haven't been upgraded to .NET 5 yet or are a project type that don't support .NET  so you don't have access to the new C# 9 features :( Or do you!?!?!?! Yes, of course you do! Most new features in C# are compiler based and not necessarily runtime based.  When you create a new project the compiler determines a default C# language based on these r…

James Montemagno James Montemagno

Use C# 8 In Any .NET Project Today

C# 8 was officially released in September at .NET Conf along side .NET Core 3 & Visual Studio 16.3 (8.3 on Mac). It is packed with tons of amazing new features [https://docs.microsoft.com/dotnet/csharp/whats-new/csharp-8?WT.mc_id=docs-montemagnoblog-jamont] that truly everyone should be using. However, there is a lot of confusing as to if you can actually use C# 8 if you aren't using .NET Core 3 or .NET Standard 2.1. * Short answer: YES! You can use it today. * Long answer: YES! Y…

James Montemagno James Montemagno

Optimizing C# Struct Equality with IEquatable and ValueTuples

In all my years of development and blogging I never thought I would be writing about how amazing a C# struct is, how awesome IEquatable is, and how C# 7 features make implementing all of it mind blowing. In Xamarin.Essentials we use the C# struct [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/struct] all over the place to encapsulate "small groups of related variables" for our event handlers. They are groups of data that don't need to be created by t…

James Montemagno James Montemagno

Paste JSON as Code with quicktype.io in Visual Studio

quicktype! Yes that quicktype [http://quicktype.io] that I blogged about late last year [https://montemagno.com/convert-json-to-any-language-with-quicktype/] on how to convert JSON to C# classes in the browser. I am back talking about it again because they have made tons of great enhancements and just today released a new extension for Visual Studio 2017 [https://marketplace.visualstudio.com/items?itemName=typeguard.quicktype-vs]! I should mention here that all of this is FREE. Watch Now, Qu…

James Montemagno James Montemagno

C# Developers: Stop Calling .Result

I love async/await Task based programming! I talk about it in all my demos, it is in all my libraries, and Frank and I did a whole Merge Conflict podcast episode [http://www.mergeconflict.fm/merge-conflict-44-i-love-callbacks] on it. The problem is that I keep getting bug reports and seeing samples where it is being abused and used completely wrong. I am never a fan of calling a lot of async code in a constructor or in the OnCreate/AppDelegate, but the real issue is when I see stuff like this w…

James Montemagno James Montemagno

My Favorite C# 7 Feature: More expression-bodied members

I can’t help myself, I love Expression-Bodied Members from C# 6! Combined with other powerful C# features it took this code: public void OnPropertyChanged(string name) { var changed = PropertyChanged; if(changed == null) return; changed(this, new PropertyChangedEventArgs(name)); } to this: public void OnPropertyChanged(string name)=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); This is amazing! However, in C# 7 things get even better. Take our goo…

James Montemagno James Montemagno

Getting Started With & Learning C#

In 2006, after years of writing C++ and Java code, while attending UAT an instructor named Phil Miller introduced me to this amazing language called C# and changed my life. It was love at first “Hello World” and I have never looked back. C# is an extremely powerful, mature, and extremely cross-platform programming language that I have been using for decades. The beauty of C# of course is that you get this amazing cross-platform framework called .NET, which gives developers ability to perform RES…

James Montemagno James Montemagno