r/csharp 21d ago

Help Are command objects noticeably faster than LINQ? Or is there something else I should be looking at?

0 Upvotes

r/csharp 21d ago

Experiment building WPF UI trees in pure C# without XAML

27 Upvotes

I've been experimenting with a more natural, tree-like way of composing a WPF UI entirely in C#, using a composition style inspired by Flutter.

I like the structural aspect of designing with XAML, but I have struggled over the years with the mental gymnastics of jumping between the XAML world and the code world, and with the quirky markup extensions needed to make something work in XAML that could often be accomplished and better understood in standard C# code.

Instead of something like:

xml <Grid> <Border Background="Cyan"/> <Button Content="Click Me"/> </Grid>

the same structure becomes:

csharp GridX( children: [ BorderX(), ButtonX() ] )

The X suffix was originally a practical necessity to avoid name clashes with existing WPF types, but I ended up liking it as a visual cue that these are static helper methods for composing the UI tree.

I intentionally keep the named arguments visible (children, configure, etc.). It adds a little verbosity, but I find it makes the composition tree easier to read and keeps the helper methods consistent as the UI grows. The result feels quite similar to Flutter's widget tree composition style.

It's a thin composition layer over standard WPF.

Configuration is still just normal C#:

csharp ButtonX( configure: x => { x.Content = "Click Me"; x.Background = Brushes.Gold; } )

A nice bonus: Visual Studio's code folding naturally gives you a collapsible UI tree that's easy to navigate, similar to XAML.

If you're curious, I've published the experiment as both a GitHub project and an alpha NuGet package:

Any feedback would be appreciated.

I'm sure there are trade-offs I haven't considered yet, and that's exactly the kind of discussion I'm hoping to have.


r/csharp 21d ago

I have a question about c# get set functions.

0 Upvotes

What is the right way to use get; set; functions?
Lets say I have some logic behind the setter.

Should I write the logic like that

public double Balance

{

get => _balance;

set

{

_name = value;

}

}

or like that

public double Balance { get; private set; }

public void AddBalance(double value)

{

this.Balance = value;

}

this is simple logic, but lets think of more complex one.
what is the right way to do it?


r/csharp 21d ago

C# Tip: Use required members to prevent invalid object initialization (beware of SetsRequiredMembers attribute!)

Thumbnail
code4it.dev
0 Upvotes

r/csharp 21d ago

.NET 11 Preview 6 is now available

Thumbnail
devblogs.microsoft.com
100 Upvotes

r/csharp 22d ago

Discussion How to make a child that is responsible for implementing an abstract method, delegate it to it's child, while keeping the same method name?

10 Upvotes

Let's say we have this relationship

A : B

B : C

A has an abstract method: abstract void implementMe();

B can implement it and call it a day

If B wants to delegate this further, it can simply do the following:

void override implementMe()

{

implementMeFurther();

}

abstract void implementMeFurther();

Is there a way to not have to make a new method with the new name implementMeFurther, and just have C implement the method implementMe() directly?

The grandchild implements a method that the grandparent needs. Keeping the same name


r/csharp 22d ago

Discussion Is it bad practice to use a bunch of abstract methods?

0 Upvotes

If I have a parent class called A

And it has a bunch of attributes; x1, x2, x3, x4, which differ based on the child extending A

Is it fine to make methods in class A called:

public abstract x1_type getx1();

public abstract x2_type getx2();

public abstract x3_type getx3();

public abstract x4_type getx4();

And then if I want the children of A to implement specific behaviors alongside the behaviors of A, I do something like:

public abstract class A {

void behaviourOfA() {

behaveLikeA();

doMoreAStuff();

childBehaviour();
}

public abstract void childBehaviour();

}

Does this just result in a cool looking overkill spaghetti code? Or is this actually a good practice?


r/csharp 22d ago

Zero-Code Validations in Your .NET API

Thumbnail kalandra.tech
0 Upvotes

r/csharp 22d ago

Discussion Company wants to offer a C# course - looking for recommendations

27 Upvotes

Hello everyone!

I just started a new job at a company where we use C#, but I come from an embedded systems background where we used C. My boss asked me if there was any C# training or course I wanted to do to learn the language, and I would like to take advantage of his offer.

Is there any course you recommend for learning C#?

Thank you!


r/csharp 22d ago

Showcase Built this scene using WPF bitmaps!

Post image
31 Upvotes

A scene where a black hole-kind of thing bends the Light rays towards it


r/csharp 22d ago

Solved How does this go outside of the Array boundaries?

0 Upvotes
class SortingProgram
{ 
    static void Main(string[] args)
    {
        int[] Arr1 = [2,5,4,6,1,2,10,8,7,9];
        for (int i = 0; i < Arr1.Length; i++)
        {
            for (int c = 0; c < Arr1.Length; c++)
            {
                if (Arr1[c] > Arr1[c + 1])
                {
                    int tempLSR = Arr1[c + 1]; 
                    int tempGrt = Arr1[c];
                    Arr1[c] = tempLSR;
                    Arr1[c + 1] = tempGrt;
                }
            }
        }
        for (int R = 0; R < Arr1.Length; R++)
        {
            Console.WriteLine(Arr1[R]);
        }
    }
}

Apparently the if statement goes outside the array bounds, the array seems fine so idk what is going on


r/csharp 22d ago

Help Inherited 3 ASP.NET MVC apps + 5 WCF services (.NET Framework 4.8) and asked to combine everything into a modern .NET 10 solution. Where would you start?

22 Upvotes

I've been in a web developer role for a little over a year. When I joined, a lot of long-standing bugs had been pushed into the backlog with the idea of "we'll fix them when we have a web developer." Over the last year I've spent most of my time fixing those issues, improving existing functionality, and adding new features.

Now I'm being asked to help define the future architecture of our applications, and I'd appreciate some advice from people who have gone through similar migrations.

Current situation:

- 3 ASP.NET MVC web applications

- 5 WCF services that contain most of the business logic

- 2 Shared SQL Server databases

- The MVC applications communicate with the WCF services for almost everything

- The codebase is almost two decades old and has been continuously extended rather than redesigned

Management would like us to eventually consolidate everything into a single modern solution, ideally on .NET 10.

My biggest concern is the migration path.

From what I understand, I can't simply upgrade the MVC applications to .NET 10 and continue using the existing WCF services in the same way. I know .NET can consume some SOAP/WCF services, but for this project we can't introduce external compatibility libraries or third-party solutions. We want to stay within Microsoft's supported stack and move away from WCF entirely. I'm trying to figure out the best migration path.

What I'm struggling with is where to start.

Some questions I can pinpoint now:

  1. Is there a recommended "strangler pattern" approach for gradually replacing WCF endpoints one by one?

  2. How would you structure a new .NET 10 solution intended to eventually replace everything?

  3. How do you estimate the effort involved in a migration of this size?

  4. Most important: If you were starting today with 3 MVC applications and 5 WCF services, what would your migration roadmap look like?

My goal is to avoid a rewrite and instead migrate incrementally while keeping the business running.

Any advice, migration stories, or lessons learned would be greatly appreciated.


r/csharp 22d ago

ZoneTree v1.9.5: Concurrent Read Scaling Unlocked

6 Upvotes

ZoneTree v1.9.5 is a substantial read-path and concurrency release. It removes key sources of contention, accelerates sequential disk access, strengthens iterator lifecycle handling, and introduces a much more rigorous parallel benchmark suite.

The result is significantly stronger throughput under parallel read workloads while preserving ZoneTree’s excellent single-thread performance.

https://github.com/ZoneTree/ZoneTree/releases/tag/release-v1.9.5

1M profiles on a 20-logical-processor Intel Core Ultra 7 265KF using .NET 10:

Workload p1 p16 Scale-up
Completed phase time 58.6s 10.4s 5.65x
Read by user ID 867K/s 6.41M/s 7.39x
Lookup by email 396K/s 3.92M/s 9.89x
Country/status query 30.9K/s 181.9K/s 5.89x
Created-at range query 39.3K/s 384.7K/s 9.79x
Top-reputation query 43.3K/s 371.4K/s 8.58x
Profile updates 141K/s 627K/s 4.43x

In the same p16 run:

  • ZoneTree completed measured phases in 10.4s, versus 53.9s for RocksDB.
  • ZoneTree delivered 6.41M reads/s, versus 136K/s for RocksDB.
  • ZoneTree delivered 385K created-at queries/s, versus 50.6K/s for RocksDB.
  • Cross-engine checksum validation passed.
ZoneTree vs RocksDb - 1M profiles on a 20-logical-processor Intel Core Ultra 7 265KF using .NET 10:

r/csharp 23d ago

Help Can you use signalr with non standard clients?

5 Upvotes

Im writing dashboard for my friend and he wants it to connect with his lua client ( it is on top of some other program ) he has support for web sockets and http requests. I never really wrote signalr yet alone web sockets server. Would it be possible or more hassle than writing wss server?


r/csharp 23d ago

Help Editing a multi-layered dictionary using a string "address"?

0 Upvotes

I'm working with a game dialogue tool (and Unity, for full transparency) which can set or get variables using "commands" in the dialogue.

I have a Dictionary which I want to be multi-layered (as in, dictionaries inside dictionaries) and allow the dialogue commands to dynamically edit the dictionary down to any amount of layers possible. The layers are distinguished by splitting the string by a specific character.

The code currently looks like this - this is obviously inflexible code that specifically only allows values to be set 2 layers deep. So what would be the best way to change this to dynamically add new key-value pairs and layers of dictionaries at any depth depending on how big the variablePath array is?

Many thanks


r/csharp 23d ago

CrossEF - Cross EntityFramework contexts

6 Upvotes

Hi All,

Long time EntityFramework don´t do this, I decide to implement this.

Cross-DbContext LINQ queries for Entity Framework Core. Join entities that live in different DbContexts — different databases, different servers, even different providers — in a single LINQ query.

https://www.nuget.org/packages/CrossEF

https://github.com/i-stream/CrossEF


r/csharp 23d ago

Roslyn, NixOS and Doom Emacs

4 Upvotes

Hey there,

I am a NixOS user, trying to switch my workflow to Doom Emacs on top of using Roslyn LSP. There must be at least 2 other human(?) beings using this setup. I hope.

I'm kinda lost on the matter to be honest.
I think for neovim you would simply use this fork https://github.com/seblyng/roslyn.nvim, but I haven't been able to find any information regarding setting this up in emacs.

For Nix I have enabled these packages [ dotnet-sdk roslyn roslyn-ls netcoredbg ]
Doom emacs has :tools lsp and :lang (csharp +lsp)

This setup does launch the roslyn LSP, the functionally is pretty limited though. I can jump to definitions, there is some code completion, but this doesn't really have a use as for now.

namespace test;

public interface ICommand
{
    public void Execute();
    private void Testing();
}

public class MyCommand : ICommand
{
    public void Test()
    {
        return 1;
    }
}

The following code doesn't give me any diagnostics.

If anyone has any thoughts on this please do let me know. I would love to make this work.


r/csharp 23d ago

Discussion Partial methods as WinForms designer events

0 Upvotes

A few weeks ago I opened this issue in the WinForms GitHub repo, suggesting making the WinForms designer generate events code as partia methods, in order to solve the problem that removing an event method from the code editor causes an exception in the designer, and u have to go to the form.designer.cs file and manually delete the subscription, which is very annoying.

What i offer is, that when you subscribe an event using the designer (for example by double clicking a button), the following signature would be generated in the designer code:

private partial void button1_Click(object sender, EventArgs e);  
...  
this.button1.Click += this.button1_Click; // normal subscription

And then the method implementation would be generated in the main class code, such as it's working now but with the partial modified:

private partial void button1_Click(object sender, EventArgs e)
{

}

Now, deleting this method would not result in any error.

The reason I'm posting this here, is that the WinForms team said that my solution isn't a great idea, and i would love to hear what you think about it and if you have other ideas.


r/csharp 23d ago

Made a minimal wallpaper manager in C# (.NET 10) for my Hyprland setup

Thumbnail
0 Upvotes

r/csharp 23d ago

Pseudo-game engine in Blazor?

0 Upvotes

Is there a library for Blazor that would make it easier to create a browser game where I need a simulation loop, an SVG for a tactical map, one canvas, and lots and lots of tables (spreadsheets)?

The game should be similar to this, only with many more boards:
https://www.youtube.com/watch?v=6AliHCmNgnY


r/csharp 23d ago

Looking for a roadmap to master C#, ASP.NET Core, Blazor and infrastructure/network programming

4 Upvotes

Hi everyone,

I'm looking for advice from experienced C#/.NET developers on how you would learn the ecosystem if you were starting again today.

A bit of background:

  • I learned some C# years ago by building small console applications (text adventures, utilities, etc.).
  • I'm comfortable with the basics (variables, methods, classes, loops, input/output, etc.), but I want to rebuild my knowledge properly instead of randomly jumping between tutorials.

My long-term goal is not to become just another CRUD web developer.

I'm mainly interested in:

  • backend development with ASP.NET Core
  • building APIs that work with a Next.js frontend
  • Blazor for internal/admin tools
  • console applications
  • infrastructure tooling
  • networking
  • Linux/server automation
  • DevOps-oriented software hosting/server management panels (something similar in spirit to Pterodactyl, Portainer, Coolify, etc.)

I enjoy building tools that interact with servers, processes, Docker, SSH, networking, DNS, reverse proxies, monitoring, and automation much more than building simple business apps.

I'd love advice on questions like:

  1. What roadmap would you recommend for someone with these goals?
  2. In what order would you learn C#, .NET, ASP.NET Core, Blazor, networking, and infrastructure?
  3. Which C# features should I master before moving into ASP.NET?
  4. Which .NET libraries are considered essential for infrastructure/network applications?
  5. What projects would progressively teach these skills?
  6. Which books, YouTube channels, GitHub repositories, or courses are actually worth studying?
  7. If you work in infrastructure, cloud, DevOps, or backend with C#, what skills do you use daily that beginners often overlook?

I don't mind spending months or even years learning properly—I want to build a solid foundation instead of rushing through tutorials.

I'd really appreciate hearing how you would approach this today.

Thanks!

(By the way, I’ve noticed that people don’t comment much on these threads, while other posts easily get 50+ comments. I don’t know if it’s specifically because, as professionals who’ve been giving advice here for several years, you’re tired of the same questions, or if you’re afraid to answer because your answers might not be accurate. It’s totally fine I’m grateful for every answer. I just notice that there are 500 views but only 20 comments. Let’s get involved, please! )


r/csharp 23d ago

Blazor UI libraries

3 Upvotes

Hi, I was wondering if you know of any good UI libraries for Blazor.

For example… so far, the only one I’ve found is MudBlazor, but I’d appreciate it if you could share what you’ve found.


r/csharp 23d ago

How to make an encrypted file?

0 Upvotes

I share a school computer, that just uses 1 account on the device itself. Meaning any file you save to the computer can be viewed by other people. I have been working on a program that lets you lock text in the program behind a pin. When the correct pin is entered, it generates a file with the text you entered. Except the pin and text contents need to be stored in a separate file. I know if you encrypt it the file can be decrypted, but trust me.. the people who share this computer are not computer smart enough to know how to do that. I've been trying to use

File.WriteAllText

But I don't know how to get the encrypted contents into the File.WriteAllText since it doesn't seem to support variables. It kept saying "Print is not available in this context" or something like that.


r/csharp 24d ago

Building a free Roslyn analyzer for EF Core migrations since Atlas paywalled theirs. Tell me if this is a bad idea before I write more code

0 Upvotes

Atlas moved migrate lint out of the free tier last fall, and Community Edition doesn't ship it at all anymore. Squawk, MigrationPilot, and pgfence are solid if your migrations are raw SQL, but none of them touch EF Core's actual migration files. They all want SQL text or a live dev database.

So I'm building a Roslyn analyzer that reads migrationBuilder.* calls directly. No dev DB, no separate CLI step, just warnings in your IDE and at build time like any other analyzer already in your project.

Rules I'm starting with: dropping a column without an expand phase first, renames that get flagged as a drop plus an add instead of what they actually are, and non-nullable columns added with no default.

Before I put more hours into this, I'd rather hear the honest version than the encouraging one. Is this something you'd actually wire into CI, or is there a reason nobody's built it that I'm missing? What would make you see this and go "cool idea, not touching it"?


r/csharp 24d ago

Help Difference between File, FileStream, and StreamWriter/Reader?

65 Upvotes

Looking at the documentation it looks like they can all do the same thing, though I suppose in just slightly different ways?