I want to look at some "best" C# code (whatever you think best or top code is).<p>Do you know public C# code that you would recommend to look at it because it is well designed or very well readable?
Follow @davidfowl on Twitter/Github and look at "Minimal API" code for beautiful C# code and examples for specific scenarios.<p>C# is <i>VERY</i> different from even just what things were 2 years ago. You can now build a full-on app with the same number of lines that a Node/Express/Flask app. Except the .NET runtime is about 5-10x faster than those runtimes.
It's an absolute massive codebase, but the compilers and analyzers in Roslyn[0] are very clearly written.<p>For a random example, here is the analyzer finding variable swaps of the form<p><pre><code> tmp = a;
a = b;
b = tmp;
</code></pre>
that can better be done using tuples:
<a href="https://github.com/dotnet/roslyn/blob/main/src/Analyzers/CSharp/Analyzers/UseTupleSwap/CSharpUseTupleSwapDiagnosticAnalyzer.cs" rel="nofollow">https://github.com/dotnet/roslyn/blob/main/src/Analyzers/CSh...</a><p>And here is the code fix that automatically performs the substitution:
<a href="https://github.com/dotnet/roslyn/blob/main/src/Analyzers/CSharp/CodeFixes/UseTupleSwap/CSharpUseTupleSwapCodeFixProvider.cs" rel="nofollow">https://github.com/dotnet/roslyn/blob/main/src/Analyzers/CSh...</a><p>[0]: <a href="https://github.com/dotnet/roslyn" rel="nofollow">https://github.com/dotnet/roslyn</a>
"DotNEXT" is a repo that enhances the code from .NET core, and has examples of using new API's that you can't even find tutorials for on the internet/examples from in public code.<p>For instance, there's been a class since .NET 6, "RandomAccess", for high-performance random-access file I/O (potentially async), and I couldn't find a single damn use of it on the internet.<p>But then this repo had a whole utility class for it, and it's chock full of similar things:<p><a href="https://github.com/dotnet/dotNext/blob/d4111528297ff3b6567b90e2295df0ac5c4b0e9f/src/DotNext.IO/IO/FileReader.cs#L135-L167" rel="nofollow">https://github.com/dotnet/dotNext/blob/d4111528297ff3b6567b9...</a><p>Similarly, I would recommend stuff by the .NET core team.<p>I'm particular biased towards the low-level/interop team. Anything by Tanner Gooding is great, stuff by Michal Strehovský, Aaron Robinson, Elinor Fung.<p>Also PathogenDavid, that guy is a wizard<p><a href="https://github.com/PathogenDavid" rel="nofollow">https://github.com/PathogenDavid</a>
The .NET source <a href="https://github.com/microsoft/referencesource" rel="nofollow">https://github.com/microsoft/referencesource</a>
<a href="https://github.com/microsoft/dotnet" rel="nofollow">https://github.com/microsoft/dotnet</a>
Unity reference source
<a href="https://github.com/Unity-Technologies/UnityCsReference" rel="nofollow">https://github.com/Unity-Technologies/UnityCsReference</a><p>The above are example of production code. I use these as references all the time<p>Awesome c# <a href="https://github.com/quozd/awesome-dotnet" rel="nofollow">https://github.com/quozd/awesome-dotnet</a>
I like the Stripe API design, and as a follow-on, I tend to like their coding styles and structures. Here's their official Stripe dotnet library - <a href="https://github.com/stripe/stripe-dotnet" rel="nofollow">https://github.com/stripe/stripe-dotnet</a>. It's well organized and the code coverage looks good.
Roslyn is the famous example of a well-maintained C# codebase. But I think it's perhaps too complex to serve as an example. It's hard to get a good overview of exactly what it does.
For some at least slightly smaller and less intimidating codebases, try for example<p><a href="https://github.com/nodatime/nodatime/" rel="nofollow">https://github.com/nodatime/nodatime/</a><p><a href="https://github.com/DapperLib/Dapper" rel="nofollow">https://github.com/DapperLib/Dapper</a>
I have had the pleasure of contributing to a couple different networked drivers with very talented maintainers that I like to use as references.<p>One supports a wide array of Framework versions and has both Sync and Async I/O, as it must to implement the ADO.NET database driver interfaces. Reading the internals really highlight the way that .NET has evolved over the years and what must be done in each target version to maximize performance:<p><a href="https://github.com/mysql-net/MySqlConnector" rel="nofollow">https://github.com/mysql-net/MySqlConnector</a><p>The other supports .NET 6 only with Async I/O only. This support policy seems to be the way that "modern" .NET development is headed, as .NET 6 will be the floor for LTS .NET (formerly .NET Core) releases in a few months. Async APIs only greatly simplify development, and make it simpler to remain performant when targeting WASM.<p><a href="https://github.com/Cysharp/AlterNats" rel="nofollow">https://github.com/Cysharp/AlterNats</a><p>As a library maintainer, one thing I often wonder about is how to indicate .NET version support. One option would be for the major version of the library to track the major version of .NET, so if I were to publish a new library today then start with .NET 6 support and start with version number 6.0.0 instead of 1.0.0. This would limit the library to only making breaking changes when the .NET version changes though.
Solutions to Advent of Code problems that people publish on github tend to be fairly short but readable, and most show off the language.<p>This is not "real" production C# code. Real production code would have a lot more checks for edge conditions and error handling that would obfuscate the meaning. But it's good in order to get a feel for the capabilities of the language and its ecosystem, imo.<p>There are a couple of repos you can browse, I recommend this one, but only if you have some basic knowledge of LINQ and/or functional programming in general, else this might scare you off. But even if you don't, you could try to figure out how the solution to the first couple of problems in each year work, and learn through that. This guy tries to use the newest features of the language so it can confusing at time. He includes the full text of the problems in the repo so you can try to understand what's he's trying to do.<p><a href="https://github.com/encse/adventofcode" rel="nofollow">https://github.com/encse/adventofcode</a><p>Also solving AOC with C# has its own github topic:<p><a href="https://github.com/topics/advent-of-code-csharp" rel="nofollow">https://github.com/topics/advent-of-code-csharp</a>
I like Bitwarden (<a href="https://github.com/bitwarden" rel="nofollow">https://github.com/bitwarden</a>), it's a great app
Just to add to the question. I suspect many developers (and perhaps especially C#) are developing CRUD apps. Are there any public repos that are CRUD apps? It seems like many public C# repos are things like libraries, frameworks, etc.
Not a .NET developer, but even as such, the Bitwarden code was very readable to me <a href="https://github.com/bitwarden/server" rel="nofollow">https://github.com/bitwarden/server</a>
In my personal opinion, the rhythm game osu! [1] and the related osu!framework [2] are great examples of C# code.<p>[1] <a href="https://github.com/ppy/osu" rel="nofollow">https://github.com/ppy/osu</a><p>[2] <a href="https://github.com/ppy/osu-framework" rel="nofollow">https://github.com/ppy/osu-framework</a>
I learned C# with notepad and RunUO as a teenager. Extremely good codebase
<a href="https://github.com/runuo/runuo" rel="nofollow">https://github.com/runuo/runuo</a>
I was looking at the CSV parser Cursively recently, and I think it is a good simple example of a high performance C# parser and API design.<p><a href="https://github.com/airbreather/Cursively" rel="nofollow">https://github.com/airbreather/Cursively</a>
<a href="https://github.com/DuendeSoftware/IdentityServer" rel="nofollow">https://github.com/DuendeSoftware/IdentityServer</a><p><a href="https://github.com/microsoft/calculator" rel="nofollow">https://github.com/microsoft/calculator</a><p>if you go on github you can browse C# repositories, there are good examples there
<a href="https://github.com/topics/csharp" rel="nofollow">https://github.com/topics/csharp</a>
Shameless plug for a site I started aimed at increasing visibility of high quality source code for language learners: <a href="http://goodsourcecode.org" rel="nofollow">http://goodsourcecode.org</a>
It is a proof of concept, and I'm always looking for people to contribute!
Nancyfx - sadly dead in the water now but well worth a read of both the code and docs <a href="https://github.com/NancyFx/Nancy/tree/master/" rel="nofollow">https://github.com/NancyFx/Nancy/tree/master/</a>
This repository is a good place to start with modern c# code, specifically ASP.NET<p><a href="https://github.com/ardalis/CleanArchitecture" rel="nofollow">https://github.com/ardalis/CleanArchitecture</a>