TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Examples of Top C# Code?

118 点作者 ycuser2超过 2 年前
I want to look at some &quot;best&quot; 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?

20 条评论

CyanLite2超过 2 年前
Follow @davidfowl on Twitter&#x2F;Github and look at &quot;Minimal API&quot; 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&#x2F;Express&#x2F;Flask app. Except the .NET runtime is about 5-10x faster than those runtimes.
评论 #33331872 未加载
评论 #33332478 未加载
评论 #33331488 未加载
评论 #33341495 未加载
评论 #33332503 未加载
kryptiskt超过 2 年前
It&#x27;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:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;roslyn&#x2F;blob&#x2F;main&#x2F;src&#x2F;Analyzers&#x2F;CSharp&#x2F;Analyzers&#x2F;UseTupleSwap&#x2F;CSharpUseTupleSwapDiagnosticAnalyzer.cs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;roslyn&#x2F;blob&#x2F;main&#x2F;src&#x2F;Analyzers&#x2F;CSh...</a><p>And here is the code fix that automatically performs the substitution: <a href="https:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;roslyn&#x2F;blob&#x2F;main&#x2F;src&#x2F;Analyzers&#x2F;CSharp&#x2F;CodeFixes&#x2F;UseTupleSwap&#x2F;CSharpUseTupleSwapCodeFixProvider.cs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;roslyn&#x2F;blob&#x2F;main&#x2F;src&#x2F;Analyzers&#x2F;CSh...</a><p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;roslyn" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;roslyn</a>
评论 #33341540 未加载
gavinray超过 2 年前
&quot;DotNEXT&quot; is a repo that enhances the code from .NET core, and has examples of using new API&#x27;s that you can&#x27;t even find tutorials for on the internet&#x2F;examples from in public code.<p>For instance, there&#x27;s been a class since .NET 6, &quot;RandomAccess&quot;, for high-performance random-access file I&#x2F;O (potentially async), and I couldn&#x27;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&#x27;s chock full of similar things:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;dotNext&#x2F;blob&#x2F;d4111528297ff3b6567b90e2295df0ac5c4b0e9f&#x2F;src&#x2F;DotNext.IO&#x2F;IO&#x2F;FileReader.cs#L135-L167" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dotnet&#x2F;dotNext&#x2F;blob&#x2F;d4111528297ff3b6567b9...</a><p>Similarly, I would recommend stuff by the .NET core team.<p>I&#x27;m particular biased towards the low-level&#x2F;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:&#x2F;&#x2F;github.com&#x2F;PathogenDavid" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;PathogenDavid</a>
ystad超过 2 年前
The .NET source <a href="https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;referencesource" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;referencesource</a> <a href="https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;dotnet" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;dotnet</a> Unity reference source <a href="https:&#x2F;&#x2F;github.com&#x2F;Unity-Technologies&#x2F;UnityCsReference" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Unity-Technologies&#x2F;UnityCsReference</a><p>The above are example of production code. I use these as references all the time<p>Awesome c# <a href="https:&#x2F;&#x2F;github.com&#x2F;quozd&#x2F;awesome-dotnet" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;quozd&#x2F;awesome-dotnet</a>
评论 #33334574 未加载
评论 #33332490 未加载
dajo超过 2 年前
I like the Stripe API design, and as a follow-on, I tend to like their coding styles and structures. Here&#x27;s their official Stripe dotnet library - <a href="https:&#x2F;&#x2F;github.com&#x2F;stripe&#x2F;stripe-dotnet" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;stripe&#x2F;stripe-dotnet</a>. It&#x27;s well organized and the code coverage looks good.
评论 #33329768 未加载
评论 #33330399 未加载
评论 #33329717 未加载
alkonaut超过 2 年前
Roslyn is the famous example of a well-maintained C# codebase. But I think it&#x27;s perhaps too complex to serve as an example. It&#x27;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:&#x2F;&#x2F;github.com&#x2F;nodatime&#x2F;nodatime&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;nodatime&#x2F;nodatime&#x2F;</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;DapperLib&#x2F;Dapper" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;DapperLib&#x2F;Dapper</a>
caleblloyd超过 2 年前
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&#x2F;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:&#x2F;&#x2F;github.com&#x2F;mysql-net&#x2F;MySqlConnector" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mysql-net&#x2F;MySqlConnector</a><p>The other supports .NET 6 only with Async I&#x2F;O only. This support policy seems to be the way that &quot;modern&quot; .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:&#x2F;&#x2F;github.com&#x2F;Cysharp&#x2F;AlterNats" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Cysharp&#x2F;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.
评论 #33335388 未加载
olvy0超过 2 年前
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 &quot;real&quot; 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&#x27;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&#x2F;or functional programming in general, else this might scare you off. But even if you don&#x27;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&#x27;s he&#x27;s trying to do.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;encse&#x2F;adventofcode" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;encse&#x2F;adventofcode</a><p>Also solving AOC with C# has its own github topic:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;topics&#x2F;advent-of-code-csharp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;topics&#x2F;advent-of-code-csharp</a>
tren超过 2 年前
I like Bitwarden (<a href="https:&#x2F;&#x2F;github.com&#x2F;bitwarden" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bitwarden</a>), it&#x27;s a great app
francisofascii超过 2 年前
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.
评论 #33332067 未加载
评论 #33332760 未加载
评论 #33333235 未加载
评论 #33334403 未加载
Sheeny96超过 2 年前
Not a .NET developer, but even as such, the Bitwarden code was very readable to me <a href="https:&#x2F;&#x2F;github.com&#x2F;bitwarden&#x2F;server" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bitwarden&#x2F;server</a>
评论 #33331056 未加载
评论 #33330762 未加载
paoda超过 2 年前
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:&#x2F;&#x2F;github.com&#x2F;ppy&#x2F;osu" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ppy&#x2F;osu</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;ppy&#x2F;osu-framework" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ppy&#x2F;osu-framework</a>
评论 #33331595 未加载
bevacqua超过 2 年前
I learned C# with notepad and RunUO as a teenager. Extremely good codebase <a href="https:&#x2F;&#x2F;github.com&#x2F;runuo&#x2F;runuo" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;runuo&#x2F;runuo</a>
评论 #33329986 未加载
mastax超过 2 年前
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:&#x2F;&#x2F;github.com&#x2F;airbreather&#x2F;Cursively" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;airbreather&#x2F;Cursively</a>
pancholopez超过 2 年前
<a href="https:&#x2F;&#x2F;github.com&#x2F;DuendeSoftware&#x2F;IdentityServer" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;DuendeSoftware&#x2F;IdentityServer</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;calculator" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;calculator</a><p>if you go on github you can browse C# repositories, there are good examples there <a href="https:&#x2F;&#x2F;github.com&#x2F;topics&#x2F;csharp" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;topics&#x2F;csharp</a>
fercircularbuf超过 2 年前
Shameless plug for a site I started aimed at increasing visibility of high quality source code for language learners: <a href="http:&#x2F;&#x2F;goodsourcecode.org" rel="nofollow">http:&#x2F;&#x2F;goodsourcecode.org</a> It is a proof of concept, and I&#x27;m always looking for people to contribute!
评论 #33330540 未加载
jimbobs超过 2 年前
Nancyfx - sadly dead in the water now but well worth a read of both the code and docs <a href="https:&#x2F;&#x2F;github.com&#x2F;NancyFx&#x2F;Nancy&#x2F;tree&#x2F;master&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;NancyFx&#x2F;Nancy&#x2F;tree&#x2F;master&#x2F;</a>
beart超过 2 年前
This repository is a good place to start with modern c# code, specifically ASP.NET<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ardalis&#x2F;CleanArchitecture" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ardalis&#x2F;CleanArchitecture</a>
评论 #33330925 未加载
stevefan1999超过 2 年前
<a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;4488073" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;4488073</a>
w4ffl35超过 2 年前
Fine tuning an AI model?
评论 #33332032 未加载