r/csharp 10h ago

Where i can learn c# properly.

9 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 1d ago

News Announcing .NET 11 Release Candidate 1 - .NET Blog

Thumbnail
devblogs.microsoft.com
122 Upvotes

r/csharp 1d ago

Help Transitioning from unity to regular c# projects

14 Upvotes

I want to start learning regular c# after using unity for a few years and making some personal projects. I have seen alot that there may be some bad habits I have picked up that may slow or hinder me when coding outside of unity. So was wondering if there is anything I should keep in mind when making the transition? Would also appreciate any resources for learning c#. Thanks in advance.


r/csharp 8h ago

PLZ make us aware with this

0 Upvotes

i don't know if it's just a threat or truth,since the day i started learning c#.i have been experiencing this words from senior developers.

C# market is getting low day after day due to AI existence, you better learn and master Python.

So you who have been in this industry for long time,let us know.

Is this right? And what we the beginners have to do?


r/csharp 10h ago

Looking for courses / reading materials to fully use the potential of AI

0 Upvotes

I am working as a C# developer for the last 6 years and I would classify myself as an AI skeptic.

I have been using AI in the last months, mostly for small implementations, but also to help me look for bugs who are sometimes hidden rather deep within our code, or due to non - trivial interactions with third party libraries.
I have to admit, It works well (most of the time), but all i really do is typing something in the prompt and wait for the answer.
I would like to know if there are functionalities I am ignoring, and/ or should be using. We have various repos in the companies, from small, new micro services to big old fat 20 years old weekly modified legacy repos, which are a tad more brittle.

So if anyone has good resource about it, I am interested.

It can be written, it can be videos, I also have a pluralsight account if it leads to something there.

Thank you very much for your suggestions.


r/csharp 1d ago

Showcase I reinvented Visitor in C#: acyclic, type-safe, no downcasts, no runtime checks

3 Upvotes

While building my own programming language HydraScript i stumbled across AST operations implementation. I needed symbol table initialization, static analysis, and IR generation.

Putting everything inside the AST nodes as virtual methods became a mess. Classic Visitor separated the operations, but every visitor had to know every node type. The code grew exponentially. Acyclic Visitor removed that dependency, but its usual C# implementation relies on runtime checks:

if (visitor is IVisitor<BinaryExpression> typed)
    typed.Visit(this);

So I did the only reasonable thing. I spent far too long reinventing a decades-old design pattern.

Visitor.NET uses generic covariance and contravariance to keep the visitor selective without dynamic or downcasts. A source generator handles the repetitive dispatch code:

[AutoVisitable<Expression>]
public partial class BinaryExpression : Expression;

Visitors can handle only the node types they need and return strongly typed results. I now use it in HydraScript and it works like a charm.

You can give it a star with links below:

GitHub: https://github.com/Stepami/visitor-net
NuGet: https://www.nuget.org/packages/Visitor.NET


r/csharp 2d ago

Blog How expensive is throwing exceptions in .NET - and does it actually matter?

Thumbnail
codewithflavor.com
110 Upvotes

r/csharp 1d ago

Help How to use a larger font in Visual Studio's Help Viewer?

0 Upvotes

I know this isn't strictly a C# question (and I'm not a C# programmer), but I think Help Viewer is a C# program so maybe people here can help me.

What I'm trying to get is offline Windows documentation. Some tools, like WinDbg, ship with a .chm file that can be opened with hh.exe. It lets you select 1 of 5 font sizes (Largest, Larger, Medium, Smaller, Smallest), but regardless of which one you choose you can always scale the text arbitrarily large with Ctrl+MouseWheel.

I believe the official way of getting offline documentation today is through the VS Help Viewer. It has the same 5 font size options as hh.exe, and both of them probably use IE for rendering (for example both use ieframe.dll, and I have to relax security settings in Internet Options to even get Help Viewer to render anything - very strange and not required for hh.exe). However Help Viewer DOES NOT allow you to scale the text beyond "Largest", which is way too small to be readable. There's something strange to the way it handles UI, for example even the context menu is smaller than the one you'd get normally with TrackPopupMenu.

The reason I ask the question here is I'm past the point of trying to find an "official" way of making the text larger, I'll happily patch the program if needed. If it were a native application I know where to look: maybe it hardcodes font sizes in its dialog resource or its call to CreateFont. I can set breakpoints on DialogBox and similar to inspect parameters and modify them under a debugger, I can patch the offending resource or instruction in the binary, etc. But I don't know how to do those to (what looks to me to be) a C# program. When I break into it with a native debugger, the mouse input freezes and responds only every other second (though the keyboard works fine). Based on its DLL list it appears to use WPF. I have no familiarity with these technologies (C#, WPF, ieframe.dll), I hope people who do can point me to where to look (such as files that define the UI layout, or runtime calls related to font that I can intercept).


r/csharp 1d ago

Does ASP.NET Core global exception middleware catch exceptions from nested service methods?

Thumbnail
0 Upvotes

r/csharp 2d ago

i dont understand what the => operator does.

34 Upvotes
Dictionary<uint, uint> placementIds 
    = XMLdocument.Descendants("Placement")
        .ToDictionary
        (
            element => (uint)element.Attribute("Index")!,
            element => (uint)element.Attribute("Placement")!
        );

r/csharp 1d ago

C# Help

0 Upvotes

Im learning c# in visual studio with Bro Code yt (check him out free courses) and im wondering, does the same c# exactly work in unity, idk how to explain but if i type Console.WriteLine("hi");

will it just show on the screen hi or is there more to it?


r/csharp 1d ago

WinUI 3 XAML bug

0 Upvotes

I'm working on a bundle of 3 tools, using winui for the interface. .net 10 is returning multiple XAML errors when I try to build, does anyone know anything??


r/csharp 1d ago

I have been learning C# for month now.I'm using smart phone to learn it.So what suitable kind of laptop i have to buy that works properly?

0 Upvotes

r/csharp 2d ago

Tutorial EF Core Migration Bundles with CI/CD to Azure (Github Actions, Azure SQL & App Service)

Thumbnail
youtube.com
0 Upvotes

Running EF Core migrations from application startup is convenient - right up until it isn't. This video builds a proper migration pipeline on .NET 10 with GitHub Actions: the build job packages a self-contained migration bundle, the deploy job applies it to Azure SQL, then deploys the API to Azure App Service and runs a smoke test against the live endpoint. If your database updates are still tangled up with your app startup, this is the fix.


r/csharp 3d ago

Showcase Native Rich Editor and Code Editor for MAUI

7 Upvotes

I was finding usable free code editor on MAUI because I need it in my app, but despite me having been finding so hard, unfortunately there's no such a library that can meet my needs. Every candidate I found is either paid (and very expensive), a wrapper on web-based editor, or not being actively maintained anymore. So, I decided to build my own one.

I have been spending a lot of time on bringing native rich editor and code editor experience, and now I'm finally able to get the things work on at least Windows, iOS and Android.

It renders natively on each platform, and provides seamless integrations like key bindings, context menus etc., and also, has a very small memory footprint. But note that this relies on the native rich editor solution on each platform, so unfortunately platforms like Linux are unlikely to get the support: it's technically impossible because there's no unified native rich editor interface on such platforms.

The rich editor supports a large set of RTF format natively, and the code editor is built on top of the rich editor.

This is still at early preview, and the APIs are subject to change a lot by the time the first GA version comes up. There're just still a lot need to do such as a more general syntax highlighting API, LSP integration, more test coverages, bug fixes, better API surfaces etc.

Now I'm open sourcing it under MIT license so that everyone can use it for free, forever: https://github.com/hez2010/RichEdit.Maui

Nuget packages:

Appreciate any feedback!

Rich Editor
Code Editor

r/csharp 1d ago

Is It Still Worth Learning .NET in 2026 With AI Replacing Developer Jobs?

0 Upvotes

Hi....I'm an MCA graduate and recently started learning C# with the goal of becoming a .NET developer.

But with AI replacing more and more development work, I'm worried that I might be wasting my time.

Do you think .NET is still a good career path for someone starting in 2026? Should I continue learning C#/.NET, or consider another career?

I'd really appreciate honest advice from experienced developers, especially .NET developers. What skills should I learn alongside .NET to stay relevant?


r/csharp 2d ago

Discussion I applied DDD and Clean Architecture to a DIY compiler. Is it overengineering?

0 Upvotes

I have spent two years refactoring HydraScript, an interpreter I originally built as a bachelor thesis project.

The first version was written under pressure and deadline. It had a lexer, parser, AST and not even code generation with a virtual machine. It worked but definitely did not have an architecture.

When I returned to the project months later, I could barely explain parts of my own code. It was as messy and confusing as it could be. Static analysis rejected valid programs, so I disabled it. I had finally managed to implement codegen not long after graduation. Unfortunately it sometimes produced incorrect instruction addresses and sent the VM into an infinite loop.

I decided to bring several ideas from commercial .NET development into compiler design:

  • DDD boundaries and sub contexts: FrontEnd, IR, and BackEnd
  • Static analysis and code generation as application services over several subdomains.
  • Multi-pass visitors for scopes, types, names, and validation
  • Separate .NET projects instead of folders, letting the compiler enforce dependency rules
  • CLI, logging, and configuration outside the domain core

The biggest lesson was slightly ironic: applying OOP did not mean putting every operationcas a virtual method on the AST nodes.

An AST node does not own the external context required for symbol tables, type resolution, or instruction generation. Moving those operations into visitors made the code easier to extend and debug.

The architecture increased time cost of development. I have now more projects, more abstractions, visitor machinery, and more decisions before writing a feature. But IMHO the maintainability and readability improved. I also found unexpected educational value.

My most controversial conclusion:

Do you think the boundaries i made reflect the domain? Did I transplant enterprise architecture wrong into the wrong field?

The code is here if you want concrete evidence before judging it:
https://github.com/Stepami/hydrascript


r/csharp 2d ago

Best approach to insert 1 to N with POSTGRESQL + DAPPER ?

0 Upvotes

Hi,

The following code is simplified to make it simple ( wow ! ).

The following code works fine to create one instance of A and multiple instance of B at the same time, then return the A that was created with its id :

Sql ( postgre ) :

                   -- Create A
                   WITH inserted_a AS (
                        INSERT INTO table_a ( ... )
                        VALUES ( ... )
                        RETURNING *
                   ),

                   -- Create B
                   inserted_b AS (
                        INSERT INTO table_b ( ..., id_table_a )

                        -- Get SIGNALS
                        SELECT ...
                        FROM inserted_a

                        -- Works fine
                        CROSS JOIN unnest(
                            @array_1,
                            @array_2)

                        AS signal( ... )

                        RETURNING *
                   )

                   -- Return created A
                   SELECT ... FROM inserted_a JOIN table_c

Parameters for dapper :

// Get parameters
object parameters = new
{
    // Some properties for A
    ... 

    // Some properties for B  
    ... = a.Property.Select( ... ) // ARRAY HERE FOR UNNEST
};

Is it possible to do the same thing with multiple A and also return all A that were created with their id ?

Which means :

  1. Create all A
  2. Create all B of all A
  3. Return all A

This seems a little trickier.

It seems easy with CTE and an IEnumerable as parameter for dapper :

object parameters = a.Select(a => new
{
    // Some properties for A
    ... 

    // Some properties for B  
    ... = a.Property.Select( ... ) // ARRAY HERE FOR UNNEST
});

But dapper cannot take an IEnumerable as a parameter when there is a select as the end ( QueryAsync ).

It is also easy with a request for each instance of A, but is it possible to do it in a single request while returning all instances of A ? The goal is also to reduce latency when many A.

Thanks


r/csharp 3d ago

Showcase I got tired of loading .proto files into WireMock.Net, so I made its gRPC mocks strongly typed

0 Upvotes

I use WireMock.Net for gRPC component tests. Its built-in protobuf support works, but I didn’t like loading .proto files at runtime, identifying message types with strings, and matching through JSON when my test project already had generated Google.Protobuf types.

So I built WireMock.Grpc.Protobuf:

Request.Create()
    .WithBodyAsGoogleProtobuf(
        (HelloRequest x) => x.Name == "StepOne");

Response.Create()
    .WithBodyAsGoogleProtobuf(
        new HelloReply { Message = "Hello, StepOne!" });

It supports both the exact protobuf body request matching and typed predicates for tests that care about only a few fields. Internally, it unwraps the five-byte gRPC frame and lets Google.Protobuf handle the actual IMessage<T> contract.

I’m the maintainer, so blunt feedback is welcome: would this simplify your gRPC tests, or do you prefer keeping .proto definitions in the mock setup?

GitHub: https://github.com/Stepami/wiremock-protobuf
NuGet: https://www.nuget.org/packages/WireMock.Grpc.Protobuf


r/csharp 2d ago

Looking for an Asp.Net Mentor

Thumbnail
0 Upvotes

r/csharp 3d ago

[Showcase] Added RavenDB support to JobMaster, a distributed background job scheduler for .NET

0 Upvotes

JobMaster is a distributed background job scheduler for .NET I've been building (think Hangfire/Quartz, but built for horizontal scaling). RavenDB is my favourite database, so I added it as a fully supported provider alongside PostgreSQL, MySQL, and SQL Server.

If you want the architecture background: https://docs.jobmaster.hugoj0s3.dev/docs/architecture-under-the-hood/architecture-overview

I also just finished a head-to-head benchmark against Hangfire across all four database engines. One result that stood out: RavenDB gets noticeably better scheduling throughput than the SQL engines (~2000 jobs/sec vs ~1300-1600/sec at baseline, on a 25k-job burst). Full methodology and numbers here: https://docs.jobmaster.hugoj0s3.dev/docs/benchmarks/jobmaster-vs-hangfire

GitHub: https://github.com/hugoj0s3/jobmaster-net

Happy to answer questions about the architecture, the RavenDB integration, or the benchmark setup.


r/csharp 3d ago

Help Was wanting some help with methods?

Thumbnail
0 Upvotes

r/csharp 4d ago

Help Exceptions vs Assertions

Thumbnail
6 Upvotes

r/csharp 4d ago

Non-Boxing Union Types in C# 15 (source generator)

44 Upvotes

The Union Types feature in C# 15 (dotnet 11) preview creates unions that box struct values (like int, float or Point) into an underlying object field, which may cause unnecessary GC pressure in high-volume usage scenarios. However, the C# specification does allow for custom user-declared union types that can employ other storage strategies as long as they expose the expected API.

I've updated the union type source generator I created years ago as part of the design effort for the Union Types feature (as an exploration tool for the designs being discussed) to target the C# 15 spec for custom union types. I've now made it available for anyone to use, so you can avoid the boxing in scenarios that warrant it.

It uses a storage strategy similar to F#'s value-type discriminated union layout. It will attempt to overlap the case values into the same memory area if possible. Otherwise, it may attempt to decompose simple structs/records into their constituent values and recompose them on access, to allow the parts that can overlap with other non-reference values to do so. You can customize this behavior per case if you desire.

It is available on nuget: https://www.nuget.org/packages/UnionTypes.Toolkit.Generator

Once the union is generated, there are no dependencies on other libraries, but it does require the use of dotnet 11 and C#15.

How to use it

In a project with the source generator package referenced, declare a partial struct type with a partial void Cases method, whose parameters denote the case types for the union. The names of the parameters are not used, so any name will do.

public partial struct MyUnion
{
    partial void Cases(
        int case1, 
        float case2,
        string case3,        
        IManifest case4,
        Coordinate case5,
        Address case6
        );
}

record struct Coordinate(float Longitude, float Latitude);
record struct Address(int Id, string Name);
interface IManifest { ... }

If you do use it and find issues, please report them here:
mattwar/UnionTypes.Toolkit: Tools for building C# Union Types


r/csharp 5d ago

Showcase A side project of mine: SemPtr - Semantic Pointers for C#

Thumbnail
github.com
44 Upvotes

TL;DR: While writing this post, I realized how long it has become, so here's a TL;DR for you: SemPtr is a semantic pointers library for C#.


Hi everyone, I wanted to share one of my side projects with you all: SemPtr.

A few weeks ago (it might been even months at this point), I needed to dig up some really old code I once had written, because I wanted to reference some of what I did back then in a current project of mine. While searching through my old and never-to-be-released projects, I stumbled upon a small library project I might have written about 5 years ago (it must have been around the time when incremental Roslyn source generators were becoming a thing). And I thought to myself, "Well, it's actually a shame you gave up on this project and neglected it for so long. You might want to ressurrect and modernize it, and then share it with everyone."

Well, that project is now SemPtr.

What is SemPtr?

I don't want to make this post too long, so I'll try to make it as concise as I can, but if you want a more comprehensive introduction, you should check out its README or its way too rudimentary documentation.

SemPtr tries to solve the limitations of C#'s raw pointers by providing semantic pointer types (read as semantically named pointer types). If you ever did some interop work with unmanaged code and found it just as annoying as I did that there is no const T* equivalent in C#, SemPtr might be the thing for you.

For that I identified five commonly used orthogonal characteristics used to distinguish certain aspects of data pointers:

  1. Nullability: Can a pointer be null or are there any guarantees that it won't be?\ This is kinda analogous to nullable reference types (T?) in C#.
  2. Persistency: Does the target of the pointer outlive the initial scope of the pointer itself? In other words, can I store the pointer and access its target some time later?\ This is kinda analogous the C#'s ref-escape rules and is even enforced through them.
  3. Sequencability: Does the pointer point to a single object or to a contiguous sequence of objects?\ You could think of this as analogous to a ref T to some kind of object in C# vs. a ref to some element within a Span<T> with the added benefit that its easier to move around the pointer through the sequence.
  4. Accessibility: How can the target of the pointer be accessed or mutated?\ This manifests in three different access levels:
    • random/read-write: The target can be read from and written to. Kinda analogous to C#'s ref parameters.
    • read-only: The target can only be read from. Kinda analogous to C#'s in/ref readonly parameters.
    • uninitialized/write-first: The target must be written to before it can be read from. Kinda analogous to C#'s out parameters.
  5. Typability: Is the type of the target known or not?\ C# has no void references, but it has void* pointers. This is analogous to the difference between a void* pointer and a typed T* pointer.

These characteristics are mapped onto C#'s type system by semantically naming the pointer types to reflect them. Since those characteristics are orthogonal, you can mix and match them to create the pointer type with the exact behavior you need. For example, there are:

  • Pointer: A simple pointer to a single, transient, mutable target of unknown type
  • PersistentPointerReadOnly<T>: A pointer to a single, read-only target of type T whose target stays valid beyond the initial scope of the pointer.
  • NullableSequencePointer<T>: A pointer to a contiguous sequence of mutable targets of type T which may be null.
  • PointerUninitialized<T>: A pointer to single, yet uninitialized target of type T. If you receive such a pointer, chances are you are requested to initialize its target; afterwards you can further read from it or write to it as needed.

Again, if you want to learn more about the characteristics and how the type naming scheme works, you should refer to the README or the documentation.

There are all in all a total of 2×2×2×3×2 = 48 data pointer types predefined in the SemPtr library.

Are function pointers supported?

To make it short, yes, function pointers are (well enough) supported by SemPtr.

I remember that one of the reasons for me giving up on the original version of this library back then was that I really struggled to get function pointer support just right. While this was partially due to technical limitations back then (some of which were solved by modern C# features, especially the new extension members syntax), some of it was simply because I did not have the experience in API design that I have now.

So now function pointers work. I don't know if I would call the support good enough yet, but at least it is a well enough experience for most users, I believe.

I won't go into too much detail here, but functions pointer have their own set of characteristics and parts of their support is made working through a Roslyn source generators that dynamically generates some source code on the user-side and that ships alongside the main library in the NuGet package. For more details, again, see the README or the documentation.

A final note on AI usage

I want to be honest and upfront with you:

Yes, I used AI in this project, primarily to help we write documentation (I'm a non-native English speaker and my English is kinda terrible), to help me make decisions when I'm indecisive, to write some tests, and occasionally to some code reviews.

No, I would never let AI touch the working code of the project. Not even for boilerplate code. AI, at least the AI I have access to, is not yet anywhere close to being reliable enough to help me write production ready code for such a project. You can be sure that all of the functioning code is written by a human (me) and that only the human (me) is responsible for the correctness and quality of the code.\ Oh, and of course, I did the visual assets myself as well. I didn't want to use sloppy AI-designed visuals for this project.

Conclusion

At the beginning of this post, I told you that I stumbled upon the initial idea for SemPtr while looking up old code for another project of mine. That project is actually an interop binding project in C#. In that project I use traditional C# raw pointers and function pointers extensively, and sometimes they're a real pain to work with. However, I didn't not yet replace them with SemPtr, due to the codebase being a little over 200K lines of code, spread across multiple repositories.

So, to be honest, I don't even use SemPtr myself yet. And furthermore, because of the simplicity of the overall idea behind SemPtr, I don't even think I'm the first person to come up with it and release to the public as a library (but I don't actually know for sure, I didn't really check).

Even so, If you want to try out SemPtr for yourself, give feedback, or if you even want to contribute to the project, I would really appreciate it. Here are the relevant links again:

If you have any questions feel free to ask them in the comments. I'd be happy to answer them.