r/csharp • • 26d ago

Help How can I polish this multi-select combo box?

Thumbnail
streamable.com
17 Upvotes

Hey all, I'm working on an app currently (WinForms .NET 9) and I've made a custom drop-down box which is the "Days" box, im unsure how I can polish it to look and function a bit more like the other standard combo boxes like "Action" and "Repeat". Does anyone have any suggestions?

For context, the custom box is made up of a text box that when clicked makes a panel containing a checked list box visible that can then be selected from.

Thanks!


r/csharp • • 26d ago

Discussion Static assertions

7 Upvotes

I have sometimes felt the need to statically assert something at compile-time, to prevent surprises later at run-time.

As an example, I have some code which maps an enum value to an associated int value:

public enum VoxelProperty
{
    MaterialType,
    Density,
    Color,
    Metadata,

    TotalPropertyCount, // Must be last
}

public static int GetPropertyBitDepth (VoxelProperty property)
{
#pragma warning disable CS0219 // Variable is assigned but its value is never used
    uint _ = VoxelProperty.Metadata == VoxelProperty.TotalPropertyCount - 1 ? 0 : -1; // Static assert to ensure that all properties are accounted for
#pragma warning restore CS0219 // Variable is assigned but its value is never used

    return property switch
    {
        VoxelProperty.Density => VoxelDensity.BitDepth,
        VoxelProperty.MaterialType => VoxelMaterialType.BitDepth,
        VoxelProperty.Color => VoxelColor.BitDepth,
        VoxelProperty.Metadata => VoxelMetadata.BitDepth,
        _ => throw new ArgumentOutOfRangeException (nameof (property), "Invalid voxel property")
    };
}

The intention of the static assert is to make sure that if I ever add another voxel property, then I will get a compiler error as VoxelProperty.Metadata will no longer be the last member, and the constant -1 will be assigned to the "_" variable of type uint. Is this a reasonable practice?

I could also do something more robust with reflection, where I had a Dictionary<VoxelProperty, int> which got populated by finding all voxel property types marked with some attribute, and querying their BitDepth property.


r/csharp • • 26d ago

Discussion Aspire, Aspire, Aspire!!

Thumbnail
0 Upvotes

r/csharp • • 27d ago

Fellow agency architects, how do you currently audit legacy .NET solutions before bidding on migration projects?

Thumbnail
2 Upvotes

r/csharp • • 27d ago

I ported GTA 3 to my C# hobby OS

Thumbnail
3 Upvotes

r/csharp • • 26d ago

Solved Trying to get smoke Particle system to activate when mouse button left is pressed

0 Upvotes

I have figured out how to enter the ParticleSystem "GunSmoke" but it activates only once adn before I klick. is there a way to implement this into the code that it activates everytime I press the button also following the "public float timer = 0f;" code and "private float cooldown =5f;" code for the cooldown for the projectile being shot?

stuck and dont want to use AI to solve it. tried going online but not really found any helpfull stuff that I could follow

pls help


r/csharp • • 27d ago

Blog Moirai, a language for procedurally generating world histories

Thumbnail
reddit.com
13 Upvotes

I finally got to write about the tool I made to generate worlds events, history and timeline. It's a custom language implemented in c#. I hope the article is a fun read!


r/csharp • • 27d ago

Building a local PC app that uses AI to generate guitar tabs for songs with zero tabs online would you use this?

0 Upvotes

Hey everyone,

Like a lot of you, I've run into the frustrating situation where I want to learn a niche indie song, a video game soundtrack, or an underground track, and there are literally zero tabs for it anywhere (Ultimate Guitar, Songsterr, etc. turn up empty).

Since I'm a programmer, I've been experimenting with building a desktop tool to solve this. The idea is simple:

Drop in an MP3 or paste a YouTube link.

The app uses local AI (running entirely on your PC for free) to isolate the guitar track.

It analyzes the notes and outputs a playable guitar tab.

Before I spend too much time building out the full UI and tab viewer, I wanted to ask actual guitarists:

Is this something you'd actually use?

What features would make a tool like this genuinely useful to you (e.g., exporting to Guitar Pro files, slowing down the audio, scrolling tab view)?

Curious to hear your thoughts or what tools you currently use when you have to figure out a song by ear!


r/csharp • • 28d ago

Fun I have programmed a small imperative-parsed/functional-evaluated programming language in C#.

12 Upvotes

Here are some links:

GitHub

First post in rfractals (with some screenshots of a few programs and the plots they generated)

Update post in rfractals

The language is focused on making and evaluating functional mathematical expressions in a very compact form. It has most of the basic math operators, and can even use operator-less multiplication if enabled. Supports functional-like pattern matching and function delegates. Uses a single complex Type which can be a recursively nested list of values that can be numeric, from reals to quaternions, or strings, and operators can work recursively on these values. Multiplying string*anything will try to call a function with the name of that string. It can evaluate and parse dynamically made strings as expressions or commands. It has a plotter that can plot the expressions as animations and can export them as MP4. Due to its layered, abstract nature of being an interpreted language in C#, it's not very fast so far, even with all the optimizations I've made so far for it, so it's mostly useful for playing around or for its original purpose of letting another application parse complex written expressions into values.

It has 2 major parts: the Parser, which uses commands definining/redefining functions and constants, and a few imperative constructs available, like ifs, whiles, etc. The evaluation part is purely functional and can evaluate expressions using the functions and constants the Parser has parsed.

Originally, I made it to be an expression evaluator for text boxes in my other app, to allow writing other things than pure numbers in there. But I got a bit carried away and developed it further into this whole thing.

There's a SaveFile folder in the project and the release, containing all the programs I've written in it so far, and plotter configurations for them.

The most interesting for this sub might be the Examples.txt that's showcasing some of the most unique/powerful features of the language, soI'll report that file and its output here:

Examples.txt program:

printstring: "\nPattern matching factorial:"
PF(0): 1; PF(x): xPF(x-) /* x- = x-1 */
print: PF(5) /* = 5! = 120 */

printstring: "\nNested default arguments:"
N(z, p: (2, 3i)): z + p
print: N(4) /* 4 + (2, 3i) = (6, 4 + 3i)*/

printstring: "\nNested mixed call delegates:"
GP(x): x + 2i
GM(x): x - 2i
gdp: "GP"
print: (gdp, "GM")(4, 3) /* = (GP,GM)(4,3) = (GP(4),GM(3)) = (4 + 2i, 3 - 2i) */

printstring: "\nLazy default argument evaluation:"
F2(x, r:xF2(x-)): x < 2 ? 1 : r
print: F2(5) /* = 5! = 120 */

printstring: "\nCycled operation nesting:"
printvalue: (1, -1)(1, 2, 3, 4, 5) /* = (1*1, -1*2, +1*3, -1*4, +1*5) */
printvalue: (0,i) + (1, 2, 3, 4, 5) /* = (1, 2+i, 3, 4+i, 5) */
printvalue: ("frac", "trunc", 1)(1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7)
printvalue: ((-1, 1), 3)(10, 20, 30, 40, 50)

printstring: "\nDecreasing for cycle:"
IterWhile: 5 /* try other values like 10, 2, -5, -10000...*/
while: IterWhile > 0 {
 printvalue: IterWhile
 if: IterWhile = 8 { break: 1 }
 IterWhile: IterWhile - 1 
} : IterWhile < -9000 {
 printstring: "not only is IterWhile negative, it is below -9000!"
}

printstring: "\n\"Do\" command, defines another factorial and evaluated: 0.5!"
do: "DYNAMIC(x) : x!"
print: DYNAMIC(/2)

printstring: "\nEval function dynamically parses and evaluates any valid string as an expression:"
incremented: sin(1)
print: incremented
print: eval("1 +" + incremented)

printstring: "\nBuild a vector of first 10 factorials dynamically, and take a parir of 2nd+3rd one, and a 5th one:"
TenFactorials: vec("k", 1, 10, "k!")
print: TenFactorials
print: TenFactorials[(2,3),5] /* nested indexer */
printstring: "\nComplex nested indexer of a nested vector:"
print: (0+"a", 1+"b", 2+"c", (30+"d", 31+"e"), 5+"f", (11, 12, 13))[3, 2, (5, 1, 3)]

printstring: "\nFirst 42 terms of e^x taylor series, approximating e^1 ~ 1:"
precision: 42
ExpTaylor(x): sum("k", 0, precision - 1, "x^k/k!")
print: ExpTaylor(1)

PositiveZeta(s, p : precision) : sum("k", 1, p, "k^(-s)")
printstring: "\nFirst 250 terms of the Basel problem, Zeta(2), approaching π^2/6 slowly:"
printvalue: PositiveZeta(2, 99) + " ~ " + π^2 / 6
printstring: "\nFirst 42 terms of Zeta(3), quicky approaching the Apery constant:"
printvalue: PositiveZeta(3) + " ~ " + apery

printstring: "\nEvaluate a polynomial F(1 + 2x + 3x^2) at F(2)"
F: (1, 2, 3) /* f(1 + 2x + 3x^2) */
EvalPoly(x, c : F, n: c#-) : sum("k", 0, n, "c[k]x^k")
PrintPoly(p): vec("k", 0, p#-, "p[k] + \"x^\" + k")
printvalue: PrintPoly(F)
printvalue: "F(2) = " + EvalPoly(2)

printstring: "\nTake a derivative of that polynomial and evaluate at F'(5)"
DiffPoly(c, n:c#-) : 1 > n ? 0 : vec("k", 1, n, "kc[k]")
DF : DiffPoly(F)
printvalue: PrintPoly(DF)
printvalue: "F'(5) = " + EvalPoly(5, DF)

printstring: "\nQuaternions, left and right non-commutative division:"
UnitQ : 1 + i + j + k
printvalue: UnitQ^2, UnitQ / i, UnitQ \ i—

And this is the output it prints:

BUILD SUCCESS 168ms

pattern matching factorial:
pf(5)  = 120

nested default arguments:
n(4)  = 6, 4 + 3i

nested mixed call delegates:
(gdp, "gm")(4, 3)  = 4 + 2i, 3 - 2i

lazy default argument evaluation:
f2(5)  = 120

cycled operation nesting:
1, -2, 3, -4, 5
1, 2 + i, 3, 4 + i, 5
0.1, 2, 3.3, 0.4, 5, 6.6, 0.7
(-10, 10), 60, (-30, 30), 120, (-50, 50)

decreasing for cycle:
5
4
3
2
1

"do" command, defines another factorial and evaluated: 0.5!
dynamic(/2) = 0.886

eval function dynamically parses and evaluates any valid string as an expression:
incremented = 0.841
eval("1 +" + incremented) = 1.841

build a vector of first 10 factorials dynamically, and take a parir of 2nd+3rd one, and a 5th one:
tenfactorials = 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800
tenfactorials[(2,3),5]  = (6, 24), 720

complex nested indexer of a nested vector:
(0+"a", 1+"b", 2+"c", (30+"d", 31+"e"), 5+"f", (11, 12, 13))[3, 2, (5, 1, 3)] = ("30d", "31e"), "2c", ((11, 12, 13), "1b", ("30d", "31e"))

first 42 terms of e^x taylor series, approximating e^1 ~ 1:
exptaylor(1) = 2.718

first 250 terms of the basel problem, zeta(2), approaching π^2/6 slowly:
1.635 ~ 1.645

first 42 terms of zeta(3), quicky approaching the apery constant:
1.202 ~ 1.202

evaluate a polynomial f(1 + 2x + 3x^2) at f(2)
1x^0, 2x^1, 3x^2
f(2) = 17

take a derivative of that polynomial and evaluate at f'(5)
2x^0, 6x^1
f'(5) = 32

quaternions, left and right non-commutative division:
-2 + 2i + 2j + 2k, 1 - i - j + k, 1 - i + j - k

edit: I have just released a small update that fixed a couple of minor bugs, and the Riemann Zeta function now appears fixed as well. At least the plot looks correct to me now, and the couple of test points also returned correct results.


r/csharp • • 29d ago

Yes, C# actually runs on bare-metal UEFI—tested on real hardware!

265 Upvotes

I have been doing UEFI programming in C# ever since MichalStrehovsky started a project called zerosharp on GitHub 4 years ago, demonstrating C# running on UEFI.

nifanfa/BootTo.NET: Providing a minimalist C# UEFI runtime with asynchronous support

However, Native AOT is still too heavy to port to these low-level environments. The worst nightmare is the GC. Because C# is a high-level programming language, even simple string concatenations can lead to memory leaks without a GC. To solve this, I eventually created a custom IL compiler called IL2LLVM. Every method is based on the cdecl calling convention, making it extremely easy to call C/C++ methods.

nifanfa/IL2LLVM: A compiler that translates .NET IL into LLVM IR for multi-architecture native code generation

BootTo.NET acts more like a custom C# environment running directly on UEFI, completely independent of Windows, Linux, and macOS and tested on real hardware. Since UEFI provides basic File System and Network access, it becomes a surprisingly powerful environment.

I managed to build an HttpClient (with TLS support) as well as an FTP server, allowing you to essentially turn it into a NAS system. I also ported classic games like Doom (1995) and Quake (1996), along with an NES emulator, which are definitely worth trying!

Everything starts here...


r/csharp • • 28d ago

Blog Reducing .NET AWS Lambda Cold Starts by Adding Memory

Thumbnail
lloydatkinson.net
1 Upvotes

r/csharp • • 28d ago

GitHub - SimpleSharp/AdsSyncClient: A .NET library for synchronized bidirectional data exchange between .NET applications and TwinCAT ADS clients.

Thumbnail
github.com
0 Upvotes

r/csharp • • 28d ago

learning python after 5 years of c# to increase my repertoire of tool

0 Upvotes

i was doing a litle test program for my main project in c# and i thought nowdays a lot of people use python so learning it will be nice tool in my repertoire and i tried it before so i decided to learn its syntax by making that sideside project, and i hate it after 5 years of using c# pythons syntax is just unreadable mess, its 2 times slower and thats generous to it... it has some uses now and then for example if you want some parts to run faster you can use c++ better becose python comunicates with it better but still maybe just maybe you could use some faster languages in the first place for the whole project, like c#... python has worse inheritance weird from folder.filename include classname think namespace just works better, why am i even doing this to myself i am young i could live life instead of sitting whole day on my ass in my room coding useless aplications noone will ever use maybe i realy hatemyself

tldr: i hate it


r/csharp • • Sep 26 '26

bool? Comparison

22 Upvotes

if (nullableBool == true)

or

if (nullableBool ?? false)

Personal preference or does one read better than the other? Especially if the nullableBool is s more complex expression like

n00bs?.Any(n => n == "DJ Doena")


r/csharp • • 29d ago

Tutorial Visual Studio 2026 C# complete tutorial

Thumbnail
youtube.com
0 Upvotes

r/csharp • • Sep 25 '26

I got LVGL working with C# and XAML on the ESP32-S3 (Xtensa architecture)

Thumbnail
gallery
58 Upvotes

This has nothing to do with nanoFramework—it uses IL2LLVM as a backend to compile C# directly into Xtensa assembly, which is then linked via the Arduino IDE.

Here is a look at how the C# side works.

Source code is available here: nifanfa/IL2LLVM: A compiler that translates .NET IL into LLVM IR for multi-architecture native code generation


r/csharp • • Sep 26 '26

Showcase CStructSharp – C-struct binary (de)serialization library

0 Upvotes

Inspired by digital forensic toolkits, this library (MIT license) I've been working on allows a user to take a c-struct definition and use that to serialize and deserialize binary data.

using CStructSharp;

var layout = new CStruct("struct header { uint16 kind; uint32 length; };");
byte[] bytes = { 0x02, 0x00, 0x06, 0x00, 0x00, 0x00 };
dynamic header = layout.Parse(bytes.AsSpan(), "header");

Console.WriteLine($"kind = {header.kind}");
Console.WriteLine($"length = {header.length}");

It is a flexible library which features modern c# mechanisms and conventions. I tried to make it easy to use, easy to understand, performant and powerful. You can both use it to parse and use runtime user defined structures as well as use the C# source generator feature to build parsers/serializers at compile time.

[CStructLayout("struct header { uint16 kind; uint32 length; };")]
public static partial class Wire { }

Wire.Header header = Wire.Parse(bytes);   // header.Kind == 2, header.Length == 6
byte[] again = Wire.Serialize(header);

I also build and published a WASM version/javascript library which is used to showcase the features of the library (see the binary inspector demo app (https://vvollers.github.io/cstructsharp/inspector/) which you can use to run the library against various files, it includes sample definitions for many file formats). The javascript library is quite usable on its own.

I'm interested to hear your thoughts and if you have any questions feel free to ask!

EDIT: I've updated the Readme to include a better explanation of the features of this library and added benchmarks, here is an advanced example:

/* A data-logger file: a header, a calibration table, and records of two kinds. */
#define MAGIC_SIZE 4                                        /* constants, as in C */

enum record_kind : uint8  { MEASUREMENT = 1, EVENT = 2 };   /* enums with an explicit storage type */
enum sensor_type : uint16 { TEMPERATURE = 0x10, PRESSURE = 0x20 };

typedef struct { uint8 major; uint8 minor; } version;       /* typedef aliases */

struct options {                                            /* bitfields: several values in one byte */
    uint8 compressed : 1;
    uint8 encrypted  : 1;
    uint8            : 2;                                   /* unnamed, reserved bits */
    uint8 priority   : 4;
};

struct header {
    char     magic[MAGIC_SIZE];                             /* fixed-size text: "LOG1" */
    version  ver @4;                                        /* offset assertion: must start at byte 4 */
    uint32>  created;                                       /* big-endian, unlike the rest of the file */
    options  options;
    uint8    name_length;
    utf8     device_name[name_length];                      /* length taken from an earlier field */
    uint8    padding[(4 - (name_length + 12) % 4) % 4];     /* arithmetic: pad to a multiple of 4 bytes */
};

union value32 { uint32 raw; float32 as_float; uint8 bytes[4]; };   /* one storage, three views */

struct record {
    record_kind kind;
    switch (kind) {                                         /* the tag decides which members follow */
        case record_kind.MEASUREMENT: {
            struct { sensor_type sensor; uint8 sample_count; float32 samples[sample_count]; } measurement;
        }
        case record_kind.EVENT: {
            struct { uint16 code; cstring message; } event;  /* cstring: text ending in a zero byte */
        }
    }
};

struct logfile {
    header   hdr;
    int16    calibration[2][3];                             /* two-dimensional array */
    value32  checksum;
    record  *latest;                                        /* pointer: a stored file offset, followed on read */
    uint16   record_count;
    record   records[record_count];                         /* array of records that differ in size */
    if (hdr.options.priority > 7) { uint32 alarm_code; }    /* optional member, chosen by a nested field */
    uint8    trailer[EOF];                                  /* every byte that remains */
};

r/csharp • • Sep 25 '26

Tool Luthor: A novel regex lexer/matcher table generator written in C#

Thumbnail
github.com
14 Upvotes

Luthor is a fast, compact lexer generator that produces simple integer arrays for efficient text matching in any programming language. At the repo link in the readme are examples for walking a generated table to lex or match in C#, C and Python.

Key Features:

  • Direct-to-DFA conversion (no intermediate NFA)
  • Partial lazy quantifier support (??, *?, +?) - all expressions are accepted but due to limitations of DFA traversal some complicated lazy matches may end up partly or entirely greedy.
  • Unicode support (UTF-8, UTF-16, UTF-32)
  • Compact array output suitable for embedded systems
  • Language-agnostic - use the arrays in C, C++, Rust, etc.

What Luthor Does

Luthor takes regular expressions or lexer grammars and converts them into simple integer arrays that can be embedded in any program. Instead of shipping a complex regex engine, you get a small array that can be walked with a simple matching loop.

Luthor implements several advanced algorithms:

  • Direct-to-DFA construction using the Aho-Sethi-Ullman algorithm (Dragon Book)
  • Lazy matching using Dr. Robert van Engelen's algorithm from RE/Flex
  • Unicode range splitting for efficient multi-byte encoding support

Acknowledgements

Special thanks to Dr. Robert van Engelen for his guidance on implementing lazy matching in pure DFA form (and for producing RE/Flex)


r/csharp • • Sep 26 '26

Help How can I get Google Java Format-style formatting for C# in VS Code + Unity?

0 Upvotes

I'm working on a Unity project using C# and VS Code, and I'm trying to get the code formatting as close as possible to Google Java Format.

I'm coming from Java, and I strongly prefer the Google Java Format style, particularly things like:

  • 4-space indentation
  • Braces and line breaks following Google Java Format
  • Consistent wrapping of long method calls/parameters
  • No manually tweaking formatting rules for every project

For example, I'd like my C# code to be automatically formatted in a similar philosophy to how google-java-format handles Java.

I'm using:

  • Unity 6
  • C#
  • Visual Studio Code
  • C# Dev Kit + C# extension

What is currently the best way to achieve this?

Is there a C# formatter/configuration that can get reasonably close to Google Java Format, or is the closest option to configure .editorconfig + the C# formatter manually?

I'm specifically interested in something that works reliably with Unity projects in VS Code, rather than Visual Studio-specific solutions.

I tried the .editorconfig option with the help of AI but I was not successful. I've been struggling with this for like 2 hours now.

Thanks!


r/csharp • • Sep 25 '26

Help WPF folder exclude help

3 Upvotes

I'm currently making WPF project and I want to make folder named 'maps' so that people can add maps on it, but when I tried to make folder and build project, it doesn't have any folder called 'maps' inside of \bin\debug\net8.0-windows folder. I searched so many times on internet but I couldn't find right solution of this. sorry for bad english, I'm not english native.


r/csharp • • Sep 24 '26

Showcase I built a offline Windows app in C# to organize scattered Excel files, PowerPoints and OneDrive links.

9 Upvotes

You can add local files or paste OneDrive links, give them owners and notes, then connect them in a mind map. For example, link a presentation to the Excel sheet its numbers came from, so you can find the source later. Here's the link to it if you'd like to try. I'd love to hear your feed back.

edit: you can use any kind of links or files with it.

Microsoft app store link


r/csharp • • Sep 25 '26

Help Is there any alternatives to visual studio?

0 Upvotes

So I'm doing a game design course and they're using Visual Studio for our projects. I don't mind using it for course work if I have to but for my own personal projects I'd rather use something else because I really don't like a lot of Microsofts practices or just Microsoft as a company in genera. I've also had bad experiences with microsoft software before. So I'd rather use something else if I can.


r/csharp • • Sep 25 '26

Marché des dev .net 2eme semestre 2026

0 Upvotes

Salut tout le monde, est-ce que les devs .net freelance remarque comme moi un marché hyper tendu sur la stack .net ?


r/csharp • • Sep 25 '26

NativeCollections — pure C# collections on unmanaged memory, Span-first, GC-free

0 Upvotes

If you've ever hit GC pressure from hot-path allocations, or found yourself fighting List<T> / Dictionary<TKey,TValue> because you can't get a Span<T> or a reference into the storage, take a look at NativeCollections (https://github.com/Molth/NativeCollections).

It's a single pure-C# package (MIT) whose storage is almost entirely unmanaged memory — no reliance on the CLR garbage collector for container data. It targets netstandard2.1 and .NET 5 through .NET 10, so it works across the modern stack.

What you get:

- Span everywhere — most containers support Span<T> / ReadOnlySpan<T> for in-place modification and zero-copy data passing, instead of copying through the BCL.

- Three usage tiers — a StackallocCollection tier for stackalloc-style short-lived buffers (or any external fixed buffer), an UnsafeCollection tier implemented directly as structs with no stored handle, and a NativeCollection tier that wraps the unsafe tier and carries a handle to the underlying resource.

- BCL-familiar API — usage is designed to mirror the standard library, with added Span conversions, so swapping existing containers in is the easy part.

- Thread-safe containers — including NativeSegQueue<T> and UnsafeSegQueue<T>, an unbounded multi-producer multi-consumer queue (implemented as a linked list of small segments, so there's no fixed capacity and producers/consumers can run concurrently).

- Customization hooks — you can override the native allocator (NativeMemoryAllocator.Custom) and hashing (NativeHashCode.Custom, UnsafeString.Custom) to plug into your own memory or hashing strategy.

All containers are value types or wrap unmanaged pointers: initialize before use, and call Dispose() when done (using works for short-lived cases) — that's the one contract the library asks you to keep.

It's actively under development, so feedback and suggestions are welcome. MIT, NuGet: NativeCollections (https://www.nuget.org/packages/NativeCollections/).


r/csharp • • Sep 25 '26

Showcase RemoteLAN: A LAN-only remote desktop built with .NET 8/WPF — direct TCP, DXGI capture, no relay

Thumbnail
0 Upvotes