r/csharp

▲ 1 r/csharp

Ressources to start building REST API as an absolute beginner

Hi everyone, hope you're doing great
As the title says, i'm looking for resources ( youtube videos, courses (free ones), books, articles...) to start building APIs. I know little about web coding (enough to make a calculator and a check list using JS and react) and a good amount about JAVA and C# and i'm trying to learn about APIs for my upcoming apprenticeship.
I tried looking youtube videos but i can't find a beginner friendly .net videos, they all required some knowledge about APIs which i don't have.
I would be grateful for any advice too.
Have a nice day !

reddit.com
u/Manmaster0z — 2 hours ago
▲ 3 r/csharp

Question on Convert.ChangeType

From Microsoft's documentation, https://learn.microsoft.com/en-us/dotnet/api/system.convert.changetype?view=net-10.0 it seems like "Convert.ChangeType(double number, typeof(int))" would return an int. However I see that in reality, the result has to still be explicitly cast afterwards like (int)Convert.ChangeType(double number, typeof(int))". From what I understand, Convert.ChangeType is changing a double to the base "object" class in the example above, and then that object still has to be converted (via the cast) to the int. So why does it require the conversiontype as an argument then? Confusing!

u/PaskettiMonster1 — 10 hours ago
▲ 10 r/csharp

Hot path overflow checks: do you try/catch? And which style would you write?

Writing checked int helpers for code that runs millions of times per program run. Two questions.

  1. Do you actually use checked() with a try catch for this? Throwing walks the stack, so I widen to long, bounds check, and return null instead (both versions in the image).

What surprises me is that everything the BCL offers here throws: checked(), int.CreateChecked, all of it. The Try convention is everywhere else in the BCL (TryParse, TryGetValue) but arithmetic never got one, and coming from Rust where checked_add just hands you an Option, that's wild to me.

  1. Style. The image shows the same method twice: one pattern-matching expression against a plain if/else. Which would you rather find in a codebase?

I'm coming from Rust so I'm obviously a declarative fanboy when I can be, but "and var sum" might be too clever for the next reader.

Where do C# people stand on these?

If the repo interests you: it's a CLI tool for Advent of Code, so you can do the whole thing from the terminal with just your session cookie, no clicking through the site to submit answers. https://github.com/scadoshi/sharpmas

u/scadoshi — 17 hours ago
▲ 34 r/csharp+1 crossposts

My Nokia 3310 Emulator in C#/Avalonia!

Hi folks!

I made, with AI assistance, Noks (terrible name, ik): an emulator of the venerable Nokia 3310, a phone that has a special place to the hearts of many, mine included. I used Avalonia and targets all of its supported platforms, including WebAssembly. It's all in pure C#/managed code goodness too! No unsafe code or pointers!

I made this because 1.) The MAME version (Nokia DCT-3) was sadly still incomplete after years since it was made. 2.) I wanted to play Space Impact authentically and everywhere. and 3.) I wanna push how far my skills can go, together with the latest agents, when it comes to reverse engineering a black-box, sparsely documented firmware and hardware.

I've started by pulling all the docs i can get my hands on old Nokia firmware modding forums, and also the prior work that MAME and Project Blacksphere did for the DCT-3 platform back in the day.

Then did a repeated loop of poking registers, memory, seeing where the firmware stops and back-tracing how me and the clanker can get pass that blocker. I also had to contend with the missing DSP Mask ROM functions that blocked the MAME effort by checking what conditions the firmware asked and responding to its requests accordingly.

Took a couple of months of on-off work but it was all worth it.

All outward facing features are implemented like the LCD, Keys, Sound, Power and RF. including an emulation of a minimal 2G GSM network that interfaces with the DSP/Baseband layer of the phone. Text and Calls were functional from my local tests using a P2P network called Waku but somehow it's broken again on deployment.

It is as fickle of a network as the real one ;)

And the configuration panel is also bit of a jank work, UI-wise, but it does the job... for now.

Hope you'll find joy in playing with the emulator as much as i did in making it!

Source code here: https://github.com/jmacato/Noks

noks.vercel.app
u/jmacato — 17 hours ago
▲ 87 r/csharp+1 crossposts

I don’t get the roadmap.sh

I learned about the internet, I already knew c# basics so it seems i should start creating projects, but i could only successfully create only one beginner project, the next one uses Github’s api which i have no clue how to use?

Also even for the first project you have to be able to use github and even that seems to be only covered later? im confused how you’re supposed to follow this map

u/Edwinbakup — 1 day ago
▲ 0 r/csharp

What is the future of C# in AI era?

Hi guys!
What is the reason to use C#/Java/etc. or any other great language that was created for humans when we are going to the world when software engineers will not write a code anymore?
Does it mean that there will be a shift to runtime efficiency (rust, C, etc) instead of dev time efficiency?

reddit.com
u/Alexander-Karpinskiy — 2 days ago
▲ 1 r/csharp

where can i learn c# for unity?

I'm a 3D/pixel art artist, but I've never known how to code. I've made a few small games using my own assets with the help of artificial intelligence, but two major problems have arisen: sometimes the AI doesn't execute commands correctly, and it's getting worse over time; and second, I hate AI, so I'd like to do everything I can to avoid using it entirely. What do you recommend?

reddit.com
u/Lopsided-Form-2626 — 1 day ago
▲ 21 r/csharp+5 crossposts

Hi everyone, I'm creating a tool to learn ASP.NET Core

I've been developing a platform for learning ASP.NET Core Web API in a more practical way for some time now. The idea is to combine guided lessons, code examples, and challenges. At the end of each challenge, you can submit your solution and receive feedback from an AI that evaluates it according to certain criteria, highlighting what you did well and the areas for improvement.

for now, the lessons use YouTube videos as support. Later, I'd like to create my own content, but first I want to validate the idea.

if you're interested, you can go to the landing page and join the waitlist to be notified when it's available. Thanks!

https://net-ascendant.vercel.app/

u/Lucky-Percentage5216 — 2 days ago
▲ 0 r/csharp

I used AI to start learning, how do I memorize the key

Hey everybody, brazilian 20 yo, u can call me Louis.

I participated on the programation of a Demo of a game like 2 years ago, in the end of my school years with 3 friends of mine. From then on, my life had some turns and I couldn't focuse on programming anymore. Came back a couple days ago and decided to start developing a software which follows the 20-20-20 rule (Each 20 minutes, look for 20 seconds to somewhere 20 feet away, to preserve your sight while using computer), but I didn't even know how to write the very first line, so I used ChatGPT to tell me what to do and then explain me how that work.

It actually turned out really well, it is functional (even tho it's kinda raw) and I do understand what I did and what those lines do mean, but I feel like if I had to start it all over again, I would be completely lost, because I couldn't memorize the codes, the main syntax behind it, and all that stuff, like how do I know if the "DispatcherTimer" is inside or outside the "private void" (I use Microsoft Visual Studio Community), and how do I learn and keep that very clear in my mind to the point I can write a full code without even thinking too much on it, is it practice?

Help me please, and just tell me if it's a hell of a sin to use AI to this, I really just don't understand yet how to study it properly. (Btw I intend to buy a course soon, but also don't know which one is trustable)

The main screen, it is the face of the app, here lies the buttons \"Start\" to start the timer, and \"Stop\" for the opposite purpose.

Still the main screen, focused on the stop button logic and what happens when the second screen is closed (the timer restarts)

Didn't comment yet, but this controls when the button on the \"Break screen\" can be clicked to close it and restart the timer on the main screen

AI disclosure: Most of the code shown in this post was generated with the help of ChatGPT. I used it as a learning tool, I asked it to explain the code and what the codes do, now I have an understanding of what the code does, the comments in the code were written by me by the way. My goal is to rewrite the project myself as I continue learning programming, not to base my knowledge on the crutch that AI is for me today.

reddit.com
u/Eu_Louis — 2 days ago
▲ 11 r/csharp+1 crossposts

anyone else not trust AI-generated tests? been trying to actually measure if they catch anything

Ok this has been bugging me for a while. I let the AI write tests, everything's green, coverage looks great... and I still don't trust any of it lol. Because the test just asserts whatever the code already does. If there's a bug in there, the test just locks it in and moves on like nothing happened.

Like, 100% coverage means nothing if the assertions are garbage, right? The only thing that actually matters is whether the test fails when the code is wrong. And nobody's sitting there checking that by hand for a wall of generated tests.

So I started messing with mutation testing for this. Basically you break the code on purpose and see if the test notices. Doesn't notice? The test is useless, toss it.

Ended up wrapping it into a little .NET tool. FsCheck for the properties, Stryker.NET does the mutation. The LLM proposes stuff, then it gets filtered pretty hard: anything that fails on working code gets dropped, anything that survives a mutant gets dropped too. You only keep what actually killed something.

Ran it on a real CliWrap commit just so I wasn't fooling myself: 2 proposed, 1 kept (with the mutant it caught), 1 thrown out for killing zero mutants. Honestly the throwing-out part is the whole point, I'd rather it show me nothing than hand me a test that does nothing.

Not gonna pretend it's some genius original thing btw. Meta does this propose-then-refute loop internally and Mutahunter is an open source take on it. Mine just does properties instead of examples, and the LLM never gets to be the judge, all the yes/no stuff is deterministic.

Anyway, mostly just curious: does anyone here actually do this in CI? Or are you all kinda just vibing and hoping the generated tests are fine lol.

reddit.com
u/Fit-Paper696 — 2 days ago
▲ 732 r/csharp

Is it true in the old days those old school devs like 40+ before they learn C#, They learned C like in the pic?

u/Wasabi-spicy00 — 4 days ago
▲ 8 r/csharp+1 crossposts

A new take on reactive programming: backend signals with GraphQL-ish queries

Just a bit context:

Reactive programming in .NET spans Rx(R3) Observables, AsyncEnumerables, Raw events. I think the most powerful one is Rx, but using it properly on the backend requires a solid grasp of multithreading, async programming, and locking, on top of its own notoriously steep learning curve of operators. Once you've internalized it, though, it's an extremely powerful paradigm.

In angular (so, javascript, single threaded), the complexity of rx has made the angular team move toward signals (at least for common reactive tasks, not as a whole substitute). This choice has been really popular since thinking with signals is easier, and code is still reactive. So i created this library fedeAlterio/SignalsDotnet, to make signals also possible on .NET.

But i wanted to make a step further. Can signals be useful also on BE?

SignalsDotnet 3.2.0 on Backend

I think they are awesome. The main issue in backend scenario is that we are multi-threaded. While signals must operate in a single-threaded world. So my solution has been basically move them into a single threaded island (of course we can have several island), we can have several of these islands, and "single-threaded" here means serialized execution, not literally one dedicated thread per island (more details on that in the README).

Step 1) Declare a class, that would be our island

https://preview.redd.it/l1co1ysxhckh1.png?width=1425&format=png&auto=webp&s=69b7d2fcd1b7dee1fdb285f78aa6b7c28eadc7bc

Everything here will run single threaded (like Wpf), in custom Synchronization Context (so async-await is handled). Dependency injection will worl as well

Step 2) Register that class as a Signal Island, and expose a SSE endpoint to query it

https://preview.redd.it/5co4l438ickh1.png?width=1276&format=png&auto=webp&s=cd1a7210ce04574d39764925e4509ea658e3d136

Step 3) We can now query that island using GraphQL-like syntax. It's just an endpoint.

https://preview.redd.it/cdkwyu1jickh1.png?width=1736&format=png&auto=webp&s=125cea944dfd5eb902c0e2ea147cfbfe7b420901

This turns out to be more powerful than GraphQL subscriptions in a sense, since every signal (property) in the island is already its own subscription, the query is just combining them together.

Step 4) Just set properties, collections, dictionaries, whatever, on the island, and they'll be pushed out through the SSE endpoint. No need to declare a subscription because everything already is a subscription, the query is only there to combine them together.

Note: There are conversion methods from Observables, AsyncEnumerables, AsyncObservables. So we can Expose them in this way too.

Note 2: The ui is completely done with claude code and claude design. Code is a mess, but its a single html file. Since its only for debugging, I didn't want to spend time on that 😂

https://preview.redd.it/4cq7ckjcjckh1.png?width=1363&format=png&auto=webp&s=0349fcb5fdffe7581fa812ce3cb7b017d79ecb02

You can find it here fedeAlterio/SignalsDotnet. There is a playground app as well to get started easily.

u/fedefex1 — 2 days ago
▲ 0 r/csharp

Hello , my api get stuck in an infinite loop each time i use a get, im using entity framework

Hello, im currently doing some practice and i already made an api , well almost, i decided , afther i creaate a list of users the appy worked well, but afther i decided to create some dummy data for the entire db , the api stop working at first i tought it was because i dint aded this lines

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings

.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize;

GlobalConfiguration.Configuration.Formatters

.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);

but i get this error

https://preview.redd.it/qpc4p4w9n8kh1.png?width=1920&format=png&auto=webp&s=af9b37836931663f1706275dc334ceb0003987b0

no redundancy in the db eighter

what its the problem here, please help , ty for the attention and God bless you all

reddit.com
u/Ok-Transition7065 — 2 days ago
▲ 4 r/csharp

Built a Managed C# Lossless Image Codec that outperforms WebP by 1.4% - 3.3% (DAI Codec Evaluation)

Hi everyone,

I wanted to share a project I've been working on: DAI (Dynamic Adaptive Image) Codec. It is a standalone lossless image codec written entirely in managed C# (targeting .NET Standard 2.0).

The main goal was to achieve higher compression ratios than WebP without relying on native C++ wrappers (like libwebp) which can be painful to manage in cross-platform .NET environments.

Key Benchmarks (Maximum Compression Ratio):

- Kodak Dataset: DAI is 3.31% smaller than WebP on average.

- DIV2K (2K High-Res Dataset): DAI is 1.47% smaller than WebP overall.

- Delta vs JPEG XL: Around +6.12% to +9.83% behind state-of-the-art.

How it works under the hood:

It uses a fully integer-reversible intra-channel correlation filter (similar to Y-CoCg-R), recursive QuadTree Variable Block-Size (VBS) partitioning from 64x64 down to 8x8, adaptive predictive modes (MedP/LOCO-I variant), and custom base-packing for specific palette streams, all feeding into a byte-aligned Brotli context window.

Project Status & Evaluation Repo:

To protect the proprietary spatial/RDO engine, the Encoder core is kept compiled inside a closed-source assembly (lib/DaiEngine.dll). However, the full Windows Forms interactive testing app, the standalone Decoder core pipeline, and the benchmarking tools are 100% open-source inside the repository.

You can clone the repo, run the WinForms sandbox app on your own BMP images, and verify the bit-exact 1:1 lossless integrity and compression ratios:

https://github.com/darkon1978-ai/DAI-Codec

Would love to hear your feedback on the architecture or ideas on optimizing the pure-managed streaming pipeline layout!

u/Darkoman78 — 2 days ago
▲ 7 r/csharp

[Showoff] Tired of DependencyProperty boilerplate? I built a Zero-Allocation Source Generator for WPF/MAUI with strict type safety.

Writing DependencyProperty in .NET UI frameworks is notoriously verbose and repetitive. Typing out DependencyProperty.Register, casting objects, and wiring metadata for every single property clutters your codebase and introduces silent runtime risks.

To solve this without sacrificing IDE responsiveness, I built Kassyi.Generators.DependencyProperty — an incremental Roslyn source generator built from the ground up for high-throughput, zero-allocation code synthesis.

1. Show Me the Code

Before (Standard Boilerplate)

public static readonly DependencyProperty IsActiveProperty =
    DependencyProperty.Register(
        nameof(IsActive),
        typeof(bool),
        typeof(MyControl),
        new PropertyMetadata(false, OnIsActiveChanged));

public bool IsActive
{
    get => (bool)GetValue(IsActiveProperty);
    set => SetValue(IsActiveProperty, value);
}

private static void OnIsActiveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    // Runtime casting and boilerplate extraction
}

After (With Generator)

[DependencyProperty<bool>("IsActive", DefaultValue = "false")]
public partial class MyControl : Control
{
    // Automatically hooked up to PropertyMetadata at compile time
    partial void OnIsActiveChanged(bool oldValue, bool newValue)
    {
        // Direct, strongly typed parameters. No casting required.
    }
}

2. Key Features

  • Single-Line Declaration: Generate the backing DependencyProperty, CLR properties, and event metadata via [DependencyProperty<T>].
  • Compile-Time Type Safety: Signature mismatches in your partial callbacks are caught immediately via Roslyn analyzer diagnostics (DPG0001), eliminating silent runtime failures.
  • Unified API Across UI Frameworks: The exact same attribute syntax compiles to the native property system for WPF, .NET MAUI, Avalonia, Uno Platform, WinUI 3, and UWP.
  • Modern C# 11+ Idioms: Leverages Generic Attributes ([DependencyProperty<T>]), target-typed new(...) AST expansion in default expressions, and auto-generated XML documentation.

3. Architecture & Performance: Zero-Allocation Pipeline

This library originates as a fork/rewrite of HavenDV's generator. When testing source generation at massive enterprise scale, frequent intermediate string concatenations during continuous typing can trigger Gen2 GC spikes, resulting in noticeable editor latency in Visual Studio and Rider.

To address this, the code synthesis pipeline was redesigned around strict zero-allocation principles:

  • ref struct Source Writers: Generation logic utilizes stack-allocated SourceWriter and ClassScope structures, completely bypassing intermediate StringBuilder and heap allocations.
  • GC Elimination: Completely removes Gen2 GC pressure during incremental analysis cycles.
  • Benchmark Results: Achieves +30% faster execution speed and +62.4% higher throughput compared to traditional string-based generation pipelines.

Your IDE stays responsive even when scaling to solutions with thousands of properties.

4. Cross-Framework Abstraction

Under the hood, framework-specific strategy handlers adapt to each platform's design differences (such as Avalonia's StyledProperty/DirectProperty, MAUI's BindableProperty, or varying callback signatures) without requiring you to change your declarations.

Target Framework Underlying Property Engine
WPF / UWP / WinUI 3 DependencyProperty.Register
.NET MAUI BindableProperty.Create
Avalonia AvaloniaProperty.Register
Uno Platform Native WinUI / UWP projections

Feedback & Contributions

The project is distributed under the MIT License and includes detailed documentation and architecture specs (in English and Japanese).

If you are working across XAML platforms and want cleaner view controls without IDE overhead, please check it out, test edge cases, and share your feedback or issues on GitHub!

reddit.com
u/kassyi — 3 days ago
▲ 7 r/csharp

MindMap desktop app (C# + Avalonia)

MindMap is a lightweight desktop app for creating and editing mind maps. It provides a pannable, zoomable canvas with quick keyboard-driven node creation, connector-based relationships, simple text alignment and color controls, outline copy/paste, undo, and image export.

Here is the github link MindMap on Github

https://preview.redd.it/8uxvdqyoz8kh1.png?width=1025&format=png&auto=webp&s=30046010ee8f6eb44cb538cde96e541ae7ca9765

It's a pretty straightforward app for quickly creating mind maps and saving them locally, without having to use a website. It's completely free and open source, with no limits or paid tiers.

I originally built it for myself because my favorite online mind-mapping tool limited free users to just three mind maps, which I found way too restrictive.

Anyway, if you find the app useful, I'd appreciate a star on the GitHub repo.

reddit.com
u/loxsmoke — 2 days ago
▲ 0 r/csharp

Andrew Troelsen Pro C# or C# player's guide , which would be better as I see Pro C # covers more of the subject . This I am asking as a beginner .

I am thinking of buying one and starting since courses are too many and I think I'm better off with some book that I can learn properly from .

reddit.com
u/Comfortable_Rip_6917 — 3 days ago
▲ 5 r/csharp

Best way to get into C#

Hello everyone, i am looking to get into programming, specifically C#, because i am interested in game development, specifically in unity, i already have a decent knowledge in computers in general and i have (sadly) vibe coded unity games before, but i have decided i wanted to learn C# and make my own things with my own creativity.

I take a gap year this year, so i have some time to get into coding, even though i am not going to be studying software engineering next year, i will be studying mechanical engineering, where i think you need some programming. What's your guys advice? How do you learn C# and make achievable goals?

reddit.com
u/Standard-Computer503 — 3 days ago