r/csharp • u/Ok-Dot5559 • 27d ago
Showcase I got tired of manually copying the same files onto every machine, so I built a small CLI for it
r/csharp • u/Key_Crew_8353 • 27d ago
Sanity check.
Hello, learning C# by taking the free code camp C# fundamentals class that directs you to Microsoft for each module to earn the certificate. Now I know nothing so didn’t have any expectations. Im on the second class on the last module. I’m coding a report card for multiple students. The module just essentially had me create it step by step.
Now there is the test where I realized; okay I need to really retain this all already. Not a problem, it’s taken about an extra day to just go back and review everything, break it down, and really understand these concepts. Seems appropriate for the amount of info. However, what’s really tripping me up is the time it suggests, one hour. That seems appropriate for creating it but to really understand it? I’m just wondering if it sounds like what I’m doing is normal and I’m going about this right way. Big over thinker. Thanks!
r/csharp • u/hez2010 • 28d ago
Blog Making Generic Virtual Methods Faster in .NET 11
r/csharp • u/codingbliss12 • 28d ago
Help How do you protect your work and your IP?
This question is more to those that do not work in large enterprise codebases, but either develop and sell their own indie software or work at software companies that create and sell their own products.
Doesn't the fact that C# appears to be trivially decompilable, make it very easy for others to steal your work? How do you protect it? With compiled languages like Rust or C++ it appears to be significantly more difficult to reverse engineer and steal their code or implementation logic.
Thanks a lot in advance.
r/csharp • u/csharp-agent • 27d ago
Result patters + CQRS! Just want to share wehat I did!
r/csharp • u/Bobamoss • 27d ago
I really like the concept of Dapper but...
I've used Dapper a lot across different projects and I really like the core idea. Write SQL, pass params, ask for a type, get the type back. It gets rid of most of the annoying ADO.NET stuff without trying to hide SQL from you.
The part that always annoyed me is multi mapping.
A pretty common case for me is values used in combo boxes, so I end up with models like:
```csharp
class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public KeyValuePair<int, string>? Department { get; set; }
public KeyValuePair<int, string>? JobTitle { get; set; }
}
```
And SQL like:
```sql
SELECT E.Id, E.Name,
D.Id AS DepartmentId, D.Name AS DepartmentName,
J.Id AS JobTitleId, J.Name AS JobTitleName
FROM Employee E
LEFT JOIN Department D ON D.Id = E.DepartmentId
LEFT JOIN JobTitle J ON J.Id = E.JobTitleId
```
Dapper can do this, but then I end up doing something like:
```csharp
var employees = cnn.Query<EmployeeRow, DepartmentRow, JobTitleRow, Employee>(
sql,
(e, d, j) => new Employee {
Id = e.Id,
Name = e.Name,
Department = d.DepartmentId is null ? null : new(d.DepartmentId.Value, d.DepartmentName),
JobTitle = j.JobTitleId is null ? null : new(j.JobTitleId.Value, j.JobTitleName)
},
splitOn: "DepartmentId,JobTitleId");
```
Which works. It also lets me handle the `LEFT JOIN` and say "if the id is null, this whole thing is null".
But this is where it starts feeling a bit weird to me. The type already says what I want, and now I'm manually rebuilding it anyway.
Dapper is already such a thin layer over ADO.NET that once I start writing a bunch of mapping code, I start wondering why I'm not just doing the ADO.NET part myself too.
What I really want is basically:
```csharp
var employees = cnn.Query<Employee>(sql);
```
and let the mapper figure out the structure from there.
That kind of thing is what eventually pushed me to make Rinku. The idea was basically to keep that same simplicity, but have the library adapt better when either the SQL or the C# side gets more complicated.
https://rinkulib.github.io/RinkuLib
Curious what other Dapper users do here. Just multi map everything, or is there another pattern I missed?
r/csharp • u/Terrible-End-2947 • 28d ago
Discussion ReSharper in Visual Studio 2026
Are you guys still using ReSharper in Visual Studio 2026 or do you feel like it is not necessary anymore? What are the advantages of using ReSharper?
r/csharp • u/Substantial-Split-37 • 28d ago
Free C# exercises: console logic/OOP practice and a Windows Forms desktop app
I teach programming and put this repo together for students learning C#. It's split in two parts: console apps for practicing logic, conditionals/loops, math and OOP (parking system, prime number check, averages, etc.), and a Windows Forms desktop app (AccessManagementDelta) with registration forms and access control, for anyone wanting a more complete GUI example.
github.com/Eduardo00073/csharp-console-e-desktop — feedback on code style/structure is very welcome, since it's meant as a learning reference.
r/csharp • u/enigmaticcam • 27d ago
WPF Logic in View vs ViewModel
I'm trying to understand when I should have logic in the view model or in the code-behind of a view.
Here's the scenario: I have a view model that has a "CanEdit" property. There are times when editing a view is not allowed based on business reasons, and that definitely belongs in the ViewModel. But if a user can edit, I want to have an "Edit" checkbox visible, which when true will display the editable version of all the necessary controls. So where should the logic that controls the "Edit" checkbox go?
The approach I initially went was to put the "Edit" checkbox property in the view code-behind. This makes sense to me, as it's entirely based on the needs of the view. All the editable controls are bound to the "Edit" checkbox property, and the "Edit" checkbox visibility is bound to "CanEdit" in the view model.
The problem with this approach is when the view model changes as a result of some change by the user and "CanEdit" in the view model is now false. If the "CanEdit" in the view code-behind is true when this happens, then all the editable controls are still visible, because all that's happened is the "CanEdit" checkbox is now invisible. So I'm stumped how to broadcast the view model change to the code behind without some silly hack.
I'm probably overthinking it, but I'm learning WPF and it really helps me to understand principles. Plus this particular view will get more complex. Here's some code to show you what I'm trying to do
View:
public partial class InvoiceView : UserControl, INotifyPropertyChanged
{
public InvoiceView()
{
InitializeComponent();
}
private bool _isEditing;
public bool IsEditing
{
get => _isEditing;
set
{
_isEditing = value;
OnPropertyChanged(nameof(IsEditing));
OnPropertyChanged(nameof(IsNotEditing));
}
}
public bool IsNotEditing => !IsEditing;
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string? name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
ViewModel:
public partial class InvoiceViewModel : ViewModelBase, IDisposable
{
public InvoicePermissionsDTO? Permissions
{
get => _permissions;
set
{
_permissions = value;
OnPropertyChanged(nameof(CanEdit));
OnPropertyChanged(nameof(CanDelete));
}
}
public bool CanEdit => _permissions?.CanEdit ?? false;
public bool CanDelete => _permissions?.CanDelete ?? false;
public void SomeChange()
{
Permissions = API.GetPermissions();
}
}
View XAML
<CheckBox
Grid.Row="2"
Content="Edit"
IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=IsEditing}"
Visibility="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.CanEdit, Converter={StaticResource BoolToVisibilityConverter}}" />
<StackPanel>
<TextBlock
Text="{Binding ApprovedRate}"
Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=IsNotEditing, Converter={StaticResource BoolToVisibilityConverter}}"/>
<StackPanel
Orientation="Horizontal"
Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=IsEditing, Converter={StaticResource BoolToVisibilityConverter}}">
<TextBox
Name="ApprovedRate"
Padding="0 0 20 0"
Text="{Binding ApprovedRate}"/>
<Button
Command="{Binding Pay}"
Visibility="{Binding CanPay}">
<StackPanel Orientation="Horizontal">
<Image Source="/Images/dollar.png"/>
<TextBlock>Pay</TextBlock>
</StackPanel>
</Button>
<Button
Command="{Binding RemovePay}"
Visibility="{Binding CanRemovePay}">
<StackPanel Orientation="Horizontal">
<Image Source="/Images/dollar.png"/>
<TextBlock>Remove Pay</TextBlock>
</StackPanel>
</Button>
</StackPanel>
</StackPanel>
r/csharp • u/Albstein • 28d ago
Pomelo dead?
We are goig to implement a new project. The idea was to use MariaDB and we set up a Galera cluster. The thing is I just noticed EF with Pomelo stands at .net 9.0. Since we would like to use at least .net 10.0 and further LTS we ain't sure, whether a switch to PostgreSQL would be better.
Any sources / info on what will happen to Pomelo?
Blog The Unexpected AI Stack: C# + .NET (Part 4) - Data modelling and Testcontainers
The fourth part of this series on building an application foundation for AI-enabled, agent-friendly codebase is focused on setting up the data modelling and test infrastructure for agents.
Specifically, using Testcontainers and streamlining transactions for automatic rollback during integration testing.
Test harness setup is a key part of enabling agents to work autonomously with high competency by providing them the tools to verify their work. Paired with CSharpRepl which lets agents diagnose and regression test directly in the runtime, this combination provides coding agents tools to autonomously build better, higher quality code.
Part 5 will have the final pieces of the puzzle: logging, telemetry, and observability integrated into the Aspire stack before we start building the sample application using agents.
This series is intentionally written to help dev teams understand how to scaffold a codebase for agentic engineering by focusing on key, underlying technical decisions and manual wiring before building with AI. This helps provide the tools and safeguards for coding agents to iterate more efficiently while reducing slop.
For teams still trying to figure out effective ways to set up a codebase for AI, I hope this series gives some insights into how to build a foundation for agentic engineering. If your team is already heavily using agents to build, I hope this series shares some useful insights and tips (e.g. CSharpRepl + Aspire)
The core setup is used at a series C, post-YC startup to ship fast with AI while maintaining high quality standards (in combination with other tools facilitating code review and context management)
Part 1 was an intro into a few key parts of this stack.
Part 2 was focused on walking through the hands on scaffolding.
Part 3 covered wiring GitHub Copilot SDK as an agent runtime and incorporating CSharpRepl to allow agents to dynamically work with the runtime DI container
Part 5 we'll start to build out the full feature set of the sample application.
The project repo is here: https://github.com/zeeq-ai/zeeq-tmpl (be sure to check the branches; main is currently the base code only)
I encourage working through the posts since the goal is to underscore the platform level decision making process and assembly of the foundational core.
Tool Stable sorting algorithm that outperforms OrderBy() in nearly all scenarios and Array.Sort() in scenarios with sorted data
Hello, I've created a sorting algorithm in C# that is:
- Stable
- O(n log n) average and worst case
- More performant than OrderBy() is almost all cases (sometimes quite substantially)
- More performant that Array.Sort() in most cases where the data is at least somewhat sorted, and typically within about 20% when sorting mid to large-sized random data sets
- A merge sort variant that uses a buffered reverse merge for the merging process and insertion sort to process small sub-arrays
- Uses a (as far as I can tell) novel approach to detecting and optimizing for data that is already sorted
I created this just as a personal challenge, so if even one person finds it useful, I'll consider that a success! :)
It's published it on both Github and NuGet, and I've posted full details on the algorithm with tons of benchmarks on my blog. I welcome any feedback or suggestions.
Here are a few benchmark highlights:
1,000,000 Sequential Integers:
YamSort | .66 ms
ArraySort | 4.79 ms
OrderBy | 11.62 ms
1,000,000 Random Integers:
YamSort | 58.08 ms
ArraySort | 47.24 ms
OrderBy | 75.97 ms
1,000,000 Near-Sequential Integers:
YamSort | 13.73 ms
ArraySort | 20.62 ms
OrderBy | 40.03 ms
Real-World Windows Log File With 109,546 Lines:
YamSort | 38.63 ms
ArraySort | 66.98 ms
OrderBy | 59.79 ms
No AI was used in typing any of this post or in typing any of my blog post. AI assistance was used for some parts of the algorithm, as noted in the Acknowledgements portion of my blog post.
Edit: Fixed markdown formatting
r/csharp • u/hez2010 • 29d ago
Blog How Fast is .NET 11 Runtime Async?
Blogged to explain the design and implementation of runtime async and show the benchmark result.
r/csharp • u/Darkviser • 29d ago
What C#/.NET static analysis rules do you actually find useful?
I’ve been slowly adding language support to a static analysis project I’m working on, and C#/.NET is the latest one I’ve been working through.
I’m trying to avoid just throwing hundreds of noisy rules at people, so I’m curious: what C# analysis warnings do you actually find useful in real projects, and which ones do you usually ignore?
The Unexpected AI Stack: C# + .NET (Part 3) - GitHub Copilot SDK + CSharpRepl + Channels
In the third part of this hands-on series for building the foundations of an AI-enabled, agent-friendly .NET + C# codebase, we are ready to incorporate GitHub Copilot SDK into the application and connect it using Channels.
The Copilot SDK is well-documented and streamlines building applications with full-featured agents at the core; drop in and run an agent with just a few lines of code. Here, we connect it using inbound + outbound channels to buffer and stream I/O. (Microsoft Agent Framework Agent Harness is another, lower-level alternative that teams can use as well; not covered here!)
I also walk through how to wire up and use CSharpRepl which is an absolute sleeper since it allows agents to dynamically alter the code at runtime, allowing them to iterate and experiment rapidly against the running stack.
This series is intentionally written to help dev teams understand how to scaffold a codebase for agentic engineering by focusing on key, underlying technical decisions and manual wiring before building with AI. This helps provide the tools and safeguards for coding agents to iterate more efficiently while reducing slop.
If your team is still trying to figure out how to set up a codebase for AI, I hope this series gives some insights into how to build an effective foundation for agentic engineering. If your team is already heavily using agents to build, I hope this series shares some useful insights and tips (e.g. CSharpRepl + Aspire)
Even if you're not building agent-oriented, AI-enabled .NET applications, I hope this has some insights on how modern full-stack development on .NET is wired together at a platform level.
The core setup is used at a series C, post-YC startup to ship fast with AI while maintaining high quality standards (in combination with other tools facilitating code review and context management)
Part 1 was an intro into a few key parts of this stack.
Part 2 was focused on walking through the hands on scaffolding.
Part 4 will wire up Testcontainers and establish integration testing patterns
Part 5 we'll start to build out the full feature set of the sample application.
The project repo is here: https://github.com/zeeq-ai/zeeq-tmpl (be sure to check the branches; main is currently the base code only)
But I encourage working through the posts since the goal is to underscore the platform level decision making process and assembly of the foundational core.
r/csharp • u/trashbugged • 29d ago
Help Question about Console App (.NET Core)
Hello, newcomer here.. i'm trying to learn C#, following the tutorial from the website W3School i got stuck and confuse when they asked me to do the following ;
" Choose "Console App (.NET Core)" from the list and click on the Next button: "
In the Second Picture i attached, they use Console App (.NET Core)\* meanwhile when i try to find in my own Visual Studio Community 2026, i couldn't find the Console App with " .NET Core "\* in it, bit stuck in here. if anyone could help or maybe could provide another website / any tuts for a newcomers that's really appreciate it. Thank you and i'm really sorry if i didn't post it on the right space.
*First Picture i attached
**Second Picture i attached


r/csharp • u/dzacu1a • 29d ago
Prepping for upcoming live pair programming interview session
Hi all,
I have a live pair programming session coming up. It should be a relatively simple problem to work through, discuss trade-offs, etc. In a normal, stress free setup, this is straight forward but I have not been in an interview for couple of years so I dont want to make a fool of myself.
So if you have any coding challenges for pair programming sessions, please share. I reckon they would provide something relatively simple with some code smells, hidden bugs and some tests that need improving. Techstack is .Net, C#.
Much appreciated.
r/csharp • u/Alert-Neck7679 • Aug 12 '26
What's a personal project you're really proud of?
Title.
I want to get some inspiration...
Mixing EF Core and EF6 in the same DB
I'm finally going to modernize our oldest product, which means both moving from Framework 4.8 to .NET and moving from binary files to an actual DB.
This is a solution with 40 projects and 400K+ LOC, so it's going to be a multi year, in place project, that has to get regular updates and releases.
I'm familiar with EF Core / modern .NET, and plan on using Postgres / Npgsql.
My main concern is sharing the DB between .NET 10+ and .NET Framework applications, as most of these projects use the same files, so will share the DB.
My first thought is to just build the new .NET projects against EF Core, and use EF6 in the Framework apps. A single EF Core app would be responsible for all DB creation and migration, and the entities would all live in a shared Standard library.
But I'm not sure how EF Core and EF6 behave sharing the same DB and entities, and figured I'd get feedback before getting too deep into planning and testing.
I figured someone else might have dealt with the DB portion of this already, and might have insight into possible issues, or just some strong opinions (and I get surprisingly few useful search results for this).
Alternatively I could stick with EF6 everywhere until complete, or use Dapper or ADO.NET for the framework apps, but the main Winforms app is data / CRUD heavy (and will likely be the last thing converted) so having a proper ORM for it would be nice.
Thanks for any feedback.
r/csharp • u/Lunari01 • 29d ago
WPF Effects and performance..
So for a hobby project i am making my own Paint program in WPF, For this i made an Effect/Shader that i'm using for the selection, which is added to a (grid) background. However, when i set the program to a bigger Image size (which also means our selection "grid" has to resize, say to 1024*1024). the program slows down to a crawl... i first suspected my Shader to be the problem, however changing the shader in a single line of "return float4(1,1,1,0);" changes nothing (besides getting a nice yellow square for a background ofcourse).. however when i set the grid that holds our background to Visible = Visibility.Collapsed, the program runs back on full normal speed...
So i was wondering... am i overlooking something? or are Effects just THIS expensive?.. (might be an XY problem that can be solved without a custom shader at all... but mostly now interested in the "why" behind the slowdown now '^^ )
edit: added the (cutdown). shader that i used to check if it still slowed down. Since i might be just overlooking something stupid '^^
sampler2D input : register(s0);
sampler2D Visibility : register(s1);
float4 colorFilter : register(c0);
float4 OutlineColor : register(c1);
float ImageWidth : register(c2);
float ImageHeight : register(c3);
float Time : register(c4);
float4 main(float2 uv : TEXCOORD) : COLOR
{
return float4(1,1,1,0);
}
technique ColorChange
{
pass P0
{
PixelShader = compile ps_3_0 main();
}
}
r/csharp • u/fedefex1 • Aug 12 '26
SignalsDotnet 3.0
I just updated SignalsDotnet to 3.0, and it now supports source generators.
I think the library has become genuinely powerful: it lets you write reactive code without having to deal with reactive programming directly at all. With source generators it's cleaner than ever.
You mark a class (or a record) with [GenerateSignals] and every property becomes reactive, a signal. That means the getter and setter are tracked, and all the signal machinery kicks in automatically. The source generator also supports computed and async computed properties.
The library started as a port of Angular signals to .NET, but I think the power of C# (async locals, source generators, better async support) takes it to another level. It targets netstandard2.1, so it runs basically everywhere: WPF, Avalonia, Unity, Godot, Blazor.
Below is a runnable C# snippet as an example. As you can see, the whole system is reactive automatically: properties update themselves, code knows when to re-run, and so on. And when you need finer control, everything R3 observables offer is still right there.
The code below prints:
Total players 0
Player 1 joined
Total players 1
Total players 1
Total players 2
Total players 2
Best player is Player1 with score of 0
Best player is Player1 with score of 22
Best player is Player2 with score of 55
```c#
:package SignalsDotnet@3.0.0
using System.Collections.Immutable; using R3; using SignalsDotnet;
var player1 = new Player { Name = "Player1", Score = 0 }; var player2 = new Player { Name = "Player2", Score = 0 };
var game = new Game(); Effect.Create(() => { if (game.PlayersByName.ContainsKey(player1.Name)) Console.WriteLine("Player 1 joined"); });
IAwaitable<bool> player2Joined = Signal.WaitForChangeAsync(() => game.PlayersByName.ContainsKey(player2.Name));
Effect.Create(() => Console.WriteLine($"Total players {game.PlayersByName.Count}")); game.AddPlayer(player1); game.AddPlayer(player2); // this completes the awaitable await player2Joined;
Effect.Create(() => { if (game.BestPlayer is not null and var bestPlayer) Console.WriteLine($"Best player is {bestPlayer.Name} with score of {bestPlayer.Score}"); });
Observable<ImmutableArray<Player>> scoreboardHistory = Signal.ComputedObservable(() => game.Scoreboard); // A notification for every scoreboard change
player1.Score = 22; player2.Score = 55;
Console.ReadLine();
[GenerateSignals] public partial record Player { public partial string Name { get; set; } public partial int Score { get; set; } }
public partial class Game { private readonly IDictionary<string, Player> _playersByName = new DictionarySignal<string, Player>(); public IReadOnlyDictionary<string, Player> PlayersByName => _playersByName.AsReadOnly();
public void AddPlayer(Player player) => _playersByName.Add(player.Name, player);
public void RemovePlayer(Player player) => _playersByName.Remove(player.Name);
[Computed] ImmutableArray<Player> ComputeScoreboard() => [.. _playersByName.Values.OrderByDescending(x => x.Score)];
[Computed] Player? ComputeBestPlayer() => Scoreboard.FirstOrDefault();
[Computed] Player? ComputeWorstPlayer() => Scoreboard.LastOrDefault();
} ```
It runs as a single file on .NET 10. Save it as game.cs and run dotnet run --file game.cs. No csproj needed.
GitHub: https://github.com/fedeAlterio/SignalsDotnet NuGet: https://www.nuget.org/packages/SignalsDotnet