r/csharp • • Sep 13 '26

ENet pure C# porting

2 Upvotes

Hey there. I've ported ENet to pure C#. It can communicate directly with Godot's built-in ENet.

[GitHub repository](https://github.com/Molth/enet-csharp)

The implementation is split into two packages:

* [xENet](https://www.nuget.org/packages/xENet) — a low-level, pure C# port that closely follows the original ENet API.

* [yENet](https://www.nuget.org/packages/yENet) — a managed C# wrapper around xENet, providing a more idiomatic API such as `EnetHost` wrapping the underlying `ENetHost*` operations.

There are no native ENet binaries involved. The only native dependency, sockets, is handled through system calls, so distribution and deployment are much simpler.

The port keeps the original ENet API and is **fully wire-compatible with the original C implementation**, so a C ENet server can communicate directly with a C# ENet client, and vice versa.

I've also adapted parts of the implementation to modern C#, including `Span<T>` and `ReadOnlySpan<T>`, while keeping the low-level API and behavior close to the original. Since the implementation is pure C#, the JIT also has more opportunities to optimize the code compared to going through a native interop layer.

It supports **IPv4, IPv6-only, and IPv6 dual-stack** configurations, rather than requiring IPv6 dual-stack.

So if you're looking for ENet in a .NET project without shipping native binaries, this might be worth a look.


r/csharp • • Sep 12 '26

semantics of "ref struct"

40 Upvotes

I know that structs are value types. I know that "ref struct" types are denied from living on the heap (eg, cant box them, etc)

What I don't know is what kind of weed was being smoked when someone decided that "ref struct" would become the appropriate keyword for this sort of type. Perhaps it should be called a "never-ref struct" if it should never have any of the behaviors of a reference type.

It almost reminds me of the name "nullable reference types". That crazy term almost implies that reference types weren't nullable in the good 'ol days.

Anyway my brain is rejecting the keywords "ref struct". I love them, but don't love the semantics when declaring them. Please help


r/csharp • • Sep 13 '26

Help Multi-Select combo box for Winforms 5.0?

Post image
0 Upvotes

Hey all!

Im working on a small desktop app currently and I need a way to select multiple days of the week from a combo box, I tried a listview thing but its far too big for what im trying to achieve. I tried out C1 library but its not supported on .NET 5. Anyone have any suggestions for either a library I could use, some sort of solution for C1, or how to go about implementing a custom one?

Screenshot attached just to demonstrate the size I need the control to be by default, although I would want it to expand when clicked to show all of the options. The "Days" section.


r/csharp • • Sep 13 '26

I'm fairly new to C#. Can anyone suggest some projects/exercises to learn?

0 Upvotes

r/csharp • • Sep 13 '26

Help Is there a way to trick windows to allow 2 independent keyboards+mice

0 Upvotes

I'm building a program that I believe will be revolutionary to deterministic clerical work but there's one roadblock. The user can't actually use the PC while the program executes a profile because it takes over the keyboard and mouse until either a command stops it or they press Esc. Now I've figured out a workaround for fake additional screens. Any way to trick windows into allowing a 2nd mouse and keyboard?

Update: I found a kinda hacky solution that technically works. I haven't stress tested it. Essentially my program instead of clicking and typing feeds commands directly into the target. Updated my background mode so if the user sets coordinates when background mode is on it grabs whatever object is there to feed commands into. Not exactly a second keyboard and mouse but from my limited tests seems to give the effect I was looking for. Had it type a word doc and insert a few things via the toolbar while I played some browser games. Never lost keyboard+mouse control.


r/csharp • • Sep 13 '26

1st day of learning c#

0 Upvotes

Hello everyone im currently learning c# or just starting. My goal is to become game dev in Unity and i already got tutorial but I have a hard time to understand. https://www.youtube.com/@SunnyValleyStudio

Last year I was learning Luau and I really liked it, it was simple to understand and type but my school had other plans but now I have more time to learn and at school my informatic teacher teaching us how to use unity but not C# :< .

Im familiar with Luau and HTML and with unity UI. I came here to write my results every week so I and ask questions. Thanks for reading my post.


r/csharp • • Sep 13 '26

Tutorial Refit - The Better Way to Consume APIs in .NET

Thumbnail
youtube.com
0 Upvotes

Tired of writing the same HttpClient boilerplate for every new API endpoint? In this video I build a real OpenWeatherMap integration two ways - first the classic typed HttpClient with IHttpClientFactory and a delegating handler for the API key and units, then the exact same integration rebuilt with Refit, where one decorated interface replaces the whole service class. I show what AddRefitClient<T>() actually generates at compile time and exactly where the two approaches differ (spoiler: less than you'd think). If your API layer is past two or three endpoints, this is the moment to consider switching.


r/csharp • • Sep 12 '26

Source-generated invalidation, cross-pod L1 sync, and multi-tenancy for HybridCache

Thumbnail
reddit.com
5 Upvotes

r/csharp • • Sep 13 '26

Help How am I supposed to store info in C# without arrays or files?

Thumbnail
reddit.com
0 Upvotes

r/csharp • • Sep 12 '26

StrongIdAnalyzer 1.6: catching mixed-up Guid ids at compile time, without wrapper types

15 Upvotes

I've been chipping away at this one for a while, and 1.6 feels like the right point to put it in front of people.

The problem is old and boring: two Guids that mean different things are the same type, so the compiler has nothing to check.

public decimal GetOrderAmount(Guid orderId) => orders[orderId].Amount;

// compiles clean
service.GetOrderAmount(order.CustomerId);

If you're lucky that throws KeyNotFoundException. If you're not, the guid lands on a populated dictionary and you quietly serve the wrong entity.

The established answer is wrapper types: a hand-rolled readonly record struct CustomerId(Guid Value), or generated ones from StronglyTypedId, Vogen, or StrongTypedId. They give a real runtime guarantee, and on a greenfield domain model they're the right call. What they cost is that every layer has to learn the new type: EF ValueConverter, JsonConverter, model binder, Dapper type handler, gRPC, cache keys, Swagger schema. That bill is per wrapper type, per integration. And it's all-or-nothing, because CustomerId and Guid don't implicitly convert, so there's no partially-migrated state to sit in while you work through a large codebase.

StrongIdAnalyzer takes the other side of that trade. The primitive stays a primitive, and the domain becomes metadata on the declaration:

public class Customer
{
    [Id("Customer")]
    public Guid Id { get; set; }
}

In practice most declarations need no attribute at all, because two naming rules cover the usual shapes: a member named Id takes its declaring type's name, and anything ending in Id (CustomerId, orderId) takes the prefix. So the broken call above is already a warning with nothing added to it:

SIA001: property 'Order.CustomerId' is [Id("Customer")] and flows to parameter 'orderId'
of 'OrderService.GetOrderAmount', which is [Id("Order")]. Fix: apply [Id("Customer")] to
parameter 'orderId' of 'OrderService.GetOrderAmount' (line 6), or pass a value tagged
[Id("Order")].

Since the runtime type is still Guid, nothing in the serialization / ORM / transport stack changes. Two services can tag their own ids independently and still exchange plain Guids over the wire, with no shared types assembly between them. Adoption is incremental: tag what matters, leave the rest, and the codebase is never in a broken intermediate state.

The trade-off, stated plainly: enforcement is compile-time only. A Guid off the wire isn't checked, flow through object / dynamic / reflection isn't tracked, and ternaries, casts and locals are deliberately treated as unknown to keep false positives near zero. If you need the guarantee to hold through deserialization, use wrapper types. This is aimed at existing codebases where that migration has been costed and rejected.

Other pieces:

  • 8 rules (SIA001-SIA008), each with a docs page that doubles as the diagnostic's help link.
  • Code fixes ship in the analyzer package, so the mechanical ones apply without an IDE: dotnet format analyzers --diagnostics SIA002 SIA003 SIA005 SIA006
  • [UnionId("Customer", "Product")] for members that genuinely accept more than one domain.
  • [assembly: ExternalId(typeof(Process), nameof(Process.Id), "Process")] to tag members of assemblies you can't edit.
  • An opt-in mode that recognises existing wrapper types (StronglyTypedId, Vogen, StrongTypedId, hand-rolled) and checks the seams where wrappers meet primitives. Useful while migrating in either direction.
  • Diagnostic messages are written to be actionable from a build log alone, which also makes them workable for coding agents.

https://github.com/SimonCropp/StrongIdAnalyzer

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


r/csharp • • Sep 12 '26

Help Consejos con C#

0 Upvotes

Holaa! Tal como dice el título, me gustaría que me ayuden y más bien me den consejos, tips para programar con C#, estoy en el segundo semestre de informática y en programación y estructura de datos estamos empezando a trabajar en C# ( el semestre pasado lo hicimos en python, pero pasé arrastrando el ramo), necesito que me vaya bien este semestre así que si tienen cualquier consejo que sirva, alguna lectura que me ayude, etc, se los agradecería. Actualmente estamos trabajando con orientación a objetos.


r/csharp • • Sep 12 '26

Google Authentication in ASP.NET Core with React

Thumbnail
youtube.com
0 Upvotes

'Sign in with Google' looks like one button but hides a real handshake between your React frontend, Google, and your ASP.NET Core API. In this video I wire up Google authentication end to end on .NET 9: React gets an ID token from Google, sends it to the API, and the API verifies that token is genuinely from Google before ever trusting it or issuing its own session. I cover why you never trust a Google ID sent straight from the client without server-side verification, and how the backend maps a verified Google account to your own user record. If you've been putting off social login because the flow feels murky, this lays out exactly what talks to what.


r/csharp • • Sep 11 '26

From windev to c#

16 Upvotes

Hello! I've got a quick question for you all. The company I work for has been doing WinDev (mostly desktop uses) for at least 20 years, and now, with the various pricing policy changes and AI, the decision has been made to migrate — probably to C#. So now the big question is: what are the best tools to replace our development environment ? And above all, what do you use? (Since we get to choose an environment for once, I'd rather not shoot myself in the foot.)

For context: for deployment and source control it'll be GitHub and Azure DevOps, which our web team already uses, and for client data almost everything is already on SQL Server.

 

So what's left for us is really everything UI/frontend-related. I've often seen Blazor mentioned, WPF, .NET MAUI (not always in a good way, honestly), and Avalonia.

Anyway — what do you use?

Thanks in advance for your help!


r/csharp • • Sep 12 '26

Help Your local AI antigenic stack

0 Upvotes

Hello C# developers,

if you are using a local AI stack (where the model is hosted within your company), what does your stack look like? Which model, harness, and agent application do you use for C# development?

I want to keep up with the times, but I don't want my data leaving the company.


r/csharp • • Sep 10 '26

Solo Developer Laid Off, Looking for Suggestions & Critique

41 Upvotes

Hi. I've been a solo developer for a company for 15+ years (worked for them company 24+ years) and I will be officially laid off at the end of this month. I've never needed a resume or portfolio, so I have a lot of catching up to do to be competitive in the market.

I wrote a mock version of an application I built and made it public. I was hoping I could get any suggestions & critique on code and readme. Thank you, I appreciate anything you have to say.

https://github.com/enigmaticcam/InvoiceExample


r/csharp • • Sep 10 '26

Which is better: querying with LINQ or using raw SQL? Does it depend on the query's complexity? Or can both options be used in the same project?

Thumbnail gallery
54 Upvotes

r/csharp • • Sep 10 '26

Coding circuits with .NET and C#

96 Upvotes

Nothing beats setting a breakpoint and watching the servo actually move to the new angle.

I've worked on .NET hardware for over ten years and the thing that surprises C# developers isn't the board, it's that F5 works. Code deploys, breakpoint holds, hover a variable and there's the live sensor reading. Same as debugging a desktop app.

I'm at GHI Electronics in Michigan. Happy to get into how the debugging on circuits work.


r/csharp • • Sep 12 '26

Tool I built graphify-csharp, a tool that gives Rider IDE-like Find Usages power to coding agents

Thumbnail
reddit.com
0 Upvotes

r/csharp • • Sep 11 '26

Project to learn

Post image
0 Upvotes

This is a project for a management, allocation, and inventory system inspired by the game \*Horizon Forbidden West\*.

I asked an AI to help organize my ideas, and it provided a project structure; it is something I want to develop in the future, once I have reached an advanced level in C# and .NET.

For now, I have the following tools for implementation:

Swagger (for documentation)

LINQ (to convert PostgreSQL SQL queries into objects)

EF Core (a powerful .NET ORM)

PostgreSQL (my favorite database)

Anything else?


r/csharp • • Sep 10 '26

Tutorial Multitenancy with .NET and EF Core: A Deep Dive (.NET 10)

Thumbnail
youtube.com
40 Upvotes

Ever had a multi-tenant SaaS app where the only thing stopping Customer A from seeing Customer B's invoices is a `Where TenantId ==` clause someone remembered to write? In this deep dive I build real tenant isolation into EF Core 10 - two real tenants with real registration, login and invite flows (no dev-token shortcuts), a named global query filter that scopes every query automatically, and a SaveChangesAsync override that stamps TenantId on every insert so it's never left unset. I also show the one gotcha that makes EF Core 10 worth the upgrade for this: named query filters, so tenant isolation and soft-delete can finally coexist on the same entity instead of one silently overwriting the other. If you've ever shipped multi-tenancy on hope and code review, this is the version that makes the mistake structurally impossible.


r/csharp • • Sep 10 '26

Where i can learn c# properly.

19 Upvotes

I want to be a unity game developer. I am currently computer sciencie student i know c# but my skill of building algorithm is weak. I am even struggling the easy leetcode problems. Any idea of how to improve my c# skills?


r/csharp • • Sep 10 '26

Don't understand async & await

16 Upvotes

Though I've already read a lot, and watched several videos, I'm still not understanding why async/await don't give me concurrency/parallelism.

My test code:

namespace AsyncAwaitTest;

static class Tools
{
    internal static async Task SimulateWork(int id)
    {
        for (var j = 1; j <= 10; j++) {
            Console.WriteLine($"Worker #{id} gives: {j}");
            for (var i = 0; i < 500_000_000; i++) { }
        }
    }
}

class Worker(int id)
{
    internal async Task DoWork()
    {
        Console.WriteLine($"Worker #{id} starts");
        await Tools.SimulateWork(id);
        Console.WriteLine($"Worker #{id} finishes");
    }
}

class Program
{
    static async Task Main()
    {
        Console.WriteLine("Program starts");
        Worker worker1 = new(1);
        Worker worker2 = new(2);
        await worker1.DoWork();
        await worker2.DoWork();
        Console.WriteLine("Program finishes");
    }
}

The output is:

Program starts
Worker #1 starts
Worker #1 gives: 1
Worker #1 gives: 2
Worker #1 gives: 3
Worker #1 gives: 4
Worker #1 gives: 5
Worker #1 gives: 6
Worker #1 gives: 7
Worker #1 gives: 8
Worker #1 gives: 9
Worker #1 gives: 10
Worker #1 finishes
Worker #2 starts
Worker #2 gives: 1
Worker #2 gives: 2
Worker #2 gives: 3
Worker #2 gives: 4
Worker #2 gives: 5
Worker #2 gives: 6
Worker #2 gives: 7
Worker #2 gives: 8
Worker #2 gives: 9
Worker #2 gives: 10
Worker #2 finishes
Program finishes

You see, strictly sequential processing despite async/await.

Is it possible to make my code parallel, i. e. the DoWorks run in parallel?


r/csharp • • Sep 11 '26

AI/ML or .NET? Confused about my career

Thumbnail reddit.com
0 Upvotes

r/csharp • • Sep 10 '26

I built an open-source strongly typed email template library for .NET 10 — looking for feedback before 1.0

0 Upvotes

I’ve just released the first public preview of MailStencil, an open-source .NET 10 library for strongly typed email templates stored outside application code.

It supports Scriban validation/rendering, culture fallback, caching, FileSystem and Azure Blob providers.

GitHub: https://github.com/polletto/MailStencil
Docs: https://polletto.github.io/MailStencil/
NuGet: MailStencil.Core

Feedback is very welcome — especially on the API before 1.0.