C#

C

C#

We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.

Join

is this not a proper use of elseif

i was pretty sure i was doing it just as the cirriculum did before, but all it activates is the daysUntilExpiration <= 10 message
No description

Using 'var' instead of explicitly stating the type

JetBrains Rider suggests I change CircleData[] circles = CircleRegistry.ToDataArray(); to var circles = CircleRegistry.ToDataArray(); with the warning:
Use 'var' (elsewhere)
I understand this is just coding style, but is it considered standard practice to use var whenever possible in C#? As someone with a bit of C++ experience this feels weird to me...

runtime size of label different from design time size, causing issue

hi guys, i'm doing a c# WinForms project for my a-level and there's an issue that's driving me crazy label14 is the label full of periods, and everything is contained in a flowlayoutpanel in design time the width is 678, and doesn't cause a horizontal scrollbar to appear; i can't change its width in design time anyway due to being contained in a flowlayoutpanel in run time however its width is somehow 702 (and now only spans two lines rather than three), and now causes the horizontal scrollbar to appear due to a small portion of it sticking outside the flowlayoutpanel width, which I do not want...
No description

SEHException (0x80004005) in CultureData.GetLocaleInfoCore

Hi, I'm trying to figure out an issue that someone's encountering when using a desktop (avalonia) app I'm a contributer of. From what I've managed to gather, they get an exception when the constructor of the XmlSerializer type is called. This exception simply crashes the entire program, even though there is a try-catch around the main function. TaskScheduler.UnobservedTaskException does set observed, but I haven't been able to verify if it was called in the first place (don't think async Tasks used like this sohuld even trigger this). ^Edit: I can verify it isn't being called....
No description

Codes runs as expected, but Unit Test keeps failing

This is the unit test that keeps the helper methods from evaluating to green ```csharp [Fact] public void SaveAndLoadGame()...
No description

āœ… ASP.Net Core Web API

Hello, I have an ASP.Net Core Web API and I am trying to add razor pages to it. Can I do it in the same project or do I need to make another seperate one? Thank you!...

Application doesnt free up ram properly for some reason

im making a custom archive packager and i have a problem with it running out of ram in debug mode(when it reaches 1.4GB) it uses way too much ram and its even more with every file it has 3 modes: misc, tex, sound in misc it compresses with zstd at max compression level in tex it goes through imageGrabber to give it a custom smaller header and decompresses the pixels and encodes them with zstd at max compression level and in sound, it doesnt compress it as its already compressed good enough...

Unity Help

I am just messing around with unity trying to see what different code does, but i cant figure out why on trigger enter is not working
No description

āœ… What's the difference between ++variable and variable++?

I understand the complier sees the compound variable operators differently depending if it's before or after the variable, but I'm not sure how. Can someone explain this to me like I'm five?

šŸ–„ļø C# WinForms + DTO (with COM Object) → šŸ”ŗ Memory Usage Problem

Hi everyone šŸ‘‹ I’m running into a memory issue in my WinForms application. I have a StudentDTO šŸ‘‰ which contains an Address class šŸ‘‰ that wraps a COM object. The Grid is bound to a collection of these DTOs....

Issue in my football match simulator

I have an issue in my football match simulator with red card events. Whenever red card events pop up, the number of players left outputted is incorrect sometimes, can someone help me figure this out? I even tried copying and resetting classes such as Player, Team and MatchProperties but nothing changes. Ping me and I'll send you the zip file.

Is writing tests like this worth it

Im using the implementations and sqlite in memory to test that the services do what they are supposed to - i guess they fall into integrations test or unit tests but i want your lots opinion https://github.com/UmbrellaCrow612/PoliceCaseManagement/blob/master/tests/Identity.Application.Tests/AuthServiceTests.cs

Update Policy for Cache of API Results

I'm busy building an MCP for my (for now just mine) Postman collections, and using the Postman API for things like fetching a list of collections, or a particular collection. This API isn't much good for analysis of any kind, even simple searches, so I'm going to cache the results in a local db that I can hopefully execute json queries on. What strategy can I use to determine when I must update the cache db? It's going to be rare that someone would use Claude just to find one collection or request, so using it not being in the cache as a trigger isn't the most sound policy. Maybe an update on every startup of the MCP, or on every n queries to it, or what?...

So this big project idea I have

I've been told the best way to learn is to do, so I'm going to put my money where my mouth is and start working on an application that helps create a character for the TTPRG Cyberpunk Red, in the same way that D&D beyond does. However I'm not quite sure where to start, I mean I know that I need to make a BUNCH of different stuff in visual studio for this but I don't know if that would be in a consoleapp, or something else, or if this would be better in python, I just want to make something that people can use and something I can put on my resume and stuff with pride. Any advice is welcome!...

Loop invariant

Hi, I'm a computer science student and i'm trying to understand loop invariant. I just know that is a proof of correctness for an algorithm and it is very similar to mathematical induction. Maybe an example will help me to understand or maybe some of you know an intuitive way to understand this subject. Thanks in advance!

āœ… Update .NET (SOLVED)

How do I update .NET? I used the dotnet.microsoft.som/en-us/download/ and got the .NET 9.0, but I don't seem to be able to use it as shown in the picture.
No description

BehaviorTree Implementation

Hello! I am working on a BehaviorTree (https://en.wikipedia.org/wiki/Behavior_tree_(artificial_intelligence,_robotics_and_control)) implementation. I need the BehaviorTree to be serializable so that it can be saved and loaded, as such I am trying to figure out how to store the leaf nodes or Tasks. My initial thought was to have a public class in my namespace that just held a bunch of static methods. Each method corresponding to a Task. A leaf node would hold the string of the method name and invoke the method via the System.Reflection library.
I then thought about a second method of using OOP to create a base class of BehaviorTreeTask and then derive new classes for each type of Task, each one overriding a base PerformTask method....

āœ… Why won't the loop loop?

```cs public class Game { public Task gameloop = Task.Factory.StartNew(() => {...

How to get value in big TagCompound

I`m making minecraft schematic analyzer in c#, and i need to get BlockList and BlockPalette from entity. It looks like this: ``` entity: (Compound) CanUpdate: 1...
Next