r/csharp • • 4h ago

Discussion C# once again the fastest web framework

Post image
144 Upvotes

With all those discussions about Microsoft porting stuff to Rust, it’s nice to see that C# does not need to hide when it comes to performance. There has been quite a lot of movement at the top of the leaderboard over the last few weeks (two weeks ago, first place was around 6850), so I’m interested to see how this race continues. This is the non-tuned section, so frameworks need to be stable and production-ready. Interestingly enough, the C# one is the most high-level of the leading frameworks, API-wise.


r/csharp • • 15h ago

Fun Average C# beginner day

9 Upvotes

r/csharp • • 1h ago

Solved c# struct padding

• Upvotes

I'm new to c# and I'm learning it just now to switch from Godot to Stride so I'm interested in Data Oriented Design. I was just now experimenting with structs with a silly example and was focused on struct padding; the string should be 8 bytes while the enum is 1 byte so i expected not more than 1 or 3 byte of padding, but the sum ends up being 16 no matter the order... does it always have to allign with the biggest field? how does this work?

using System.Runtime.InteropServices;


[StructLayout(LayoutKind.Explicit)]
struct Entity {
    public enum Race : byte { ALIEN, HUMAN };
    static private int _max_rand_num = 9999;
    static private string[][] _possibleNames = {
        new string[]{"Vorp", "Zeep", "Bizr", "Zub", "Wobt"},    // alien names
        new string[]{"Carl", "Greta", "Seb", "Xiang", "Sierra"} // human names
    };

    [FieldOffset(0)] public readonly string name;
    [FieldOffset(8)] public readonly Race race;

    public Entity()
    {
        Random rand = new Random();
        race = (Race)rand.Next(Enum.GetValues(typeof(Race)).Length);
        string[] race_names = _possibleNames[(int)race];
        name = race_names[rand.Next(0, race_names.Length)] + rand.Next(_max_rand_num);
    }

    public override string ToString()
    {
        return $"Race: {race}, Name: {name}";
    }
}


class Program {
    public static unsafe void Main(string[] args)
    {
        Entity rand_entity = new Entity();
        Console.WriteLine(
            $"{rand_entity}, string size = {sizeof(string*)}, enum size = {sizeof(Entity.Race)}, together = {sizeof(Entity)}");
    }
}

r/csharp • • 15h ago

Beginner question about creating new variables at runtime?

0 Upvotes

Hello,im creating a map terrain generator on the terminal with visual studio. In this generator, based on a random number, it decides how many mountains the map will have, my question was, how do I create more mountain y and x position variables at runtime when the random number is decided? thanks.


r/csharp • • 2h ago

Blog Async in F#, C# and TypeScript, and where task { } in Fable stands as of 5.21

Thumbnail
0 Upvotes

r/csharp • • 15h ago

I built QuickRun, a modern Win+R replacement for Windows 11 using WinUI 3

Thumbnail
gallery
0 Upvotes

Hi everyone,

I've been working on QuickRun, an open-source launcher inspired by the classic Windows Run dialog.

It's built with WinUI 3 and .NET 8 and focuses on providing a modern Windows 11 experience while keeping the simplicity of Win+R.

Current features:

• Built-in calculator

• Automatic desktop app discovery

• Microsoft Store app support

• Command suggestions

• URL launching

• Windows system commands

• Command arguments support

The project is open source and I'd love to get feedback from the Windows community.

GitHub:

https://github.com/GiosuOffice/QuickRun