Welcome to C# 11
devblogs.microsoft.com
devblogs.microsoft.com
The language has gotten a lot of new features but it is surprisingly viable to keep coding like it's 2012 when C# 5.0 came out with async/await support.
It is also surprisingly viable for most C# programmers to not keep up with new language feature. Most are using ReSharper or Rider that will introduce useful new language features as a refactoring suggestion that is one shortcut away.
Your best bet is install visual studio (free) and start messing with it.
It might piss people off, but for a new learner like me it's really useful. Plus, I don't have the luxury to count on my colleagues to get some code review, therefore the closest I get is the available tools (clang-tidy, clang-format and enable_developer_options in the project_options[0] extension).
T AddAll<T>(params T[] elements) where T : IMonoid<T> =>
elements switch
{
[] => T.Zero,
[var first, ..var rest] => first + AddAll<T>(rest),
};
It is remarkable how functional C# has become. Not that it wasn't very functional already, what with LINQ and its (much more powerful than Java) generics but the above example really hammers home how much FP has inspired C#, on top of Ocaml's influence on C# generics[0].[0]: https://github.com/ocaml/cwn-data/blob/9ee93e99d984b3f922e25...
var paymentId =
from joshIban in processor.GetIban("josh") // fails
from olenaIban in processor.GetIban("olena") // not executed
from paymentId in processor.SendPayment(joshIban, olenaIban, 100)
select paymentId;
https://github.com/louthy/language-ext/wiki/Thinking-Functio...Yeah, it's also interesting to point out how useful to FP C# 11's further improvements to generics are. Generic Math, which the IMonoid<T> in this example is a part of explaining a small related piece of (static abstract interfaces), is another place where C# is improving generics (further beyond Java).
The list of interfaces in the much expanded System.Numerics namespace where most of the raw implementation of Generic Math lives should look quite interesting, if not familiar, to many FP developers: https://learn.microsoft.com/en-us/dotnet/api/system.numerics...
It will be interesting to see where libraries take Generic Math.
This particular form of raw strings would seem to have the problem that you can't start the raw string with a double-quote character. ie if you want:
Console.WriteLine(???);
... to print: "Hello world"
... you can't write: Console.WriteLine(""""Hello world"""");
... because that'll print: Hello world
I suppose the workaround is: Console.WriteLine("""
"Hello world"
""");Another thing to keep in mind is that all of these changes are available to F# too, and static members in interfaces (plus some extra syntax goodness around SRTPs that they are introducing) are gonna be amazing (interfaces + static members are starting to look eerily close to typeclasses, in a good way)