C#

C

C#

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

Join

App.xaml

Hi guys, I'm fairly new to C# & WPF, but I'm trying to make some basic macro scripts, but I'm running into a problem and I can't seem to figure out whats the problem. I keep getting the error that my 'class' property not exist in the XML namespace, but it's cleary there. What am I missing?...
No description

(MONOGAME )How to pass a method with parameters to the update method

i have 3 classes. player,map and game 1 i have a rectangle for my player and the plattfroms that are generated by a textfile. I made a method for them and tried passing it to the update method but it wont accept it since it got paramteres. How do i fix it?
No description

Returning Service result to Controller (Minimal API)

```csharp /// <summary> /// Deletes a reservation by its ID. /// </summary> /// <param name="reservationId">ID of the reservation to delete.</param>...

Remove-Migration and Add Migration not correctly working how i expected

When I remove the latest Migration and then add later a migration then changes from previus migrations is also added in the new migration altough i just deleted the latest migration. This is a behaviour which i want to avoid, what can i do to avoid such side effects?...

Building Constructors 101

Not to familiar with C# personally but I'm using it with Unity for a project-based class I'm taking. I'm trying to build a state machine, where there's the BaseState interface and StateMachine class. In my StateMachine class I have a constructor that takes a BaseState defaultState parameter. I want it to be able to take classes that implement/inherit from the BaseState interface like IdleState or PatrolState, but I really don't have a clue how to do that.

✅ Ef Core unexpected query behaviour

```cs var memberships = await db.OrganizationMembers.AsTracking() .Include(om => om.Organization) .Where(om => om.UserId == user.Id && om.InvitationStatus == InvitationStatus.Approved && om.Role > MemberRole.None)...

Dictionary vs switch in source generated code

I have doubt. Im generating a compiled communication framework and the "endpoint handler" is a dictionary is int64 key-based with actions processing the context. keyvalue pairs are generated with my source generator. My question is. if I generate the equivalent switch to handle like 150 cases in compile time. would be inefficient?...

✅ File.WriteAllBytesAsync fails to download to bin folder with no error

This is the code I have currently ```csharp RestRequest request = new($"/d/{id}", Method.Get); byte[]? response = await client.DownloadDataAsync(request); //location is Path.Combine(Environment.CurrentDirectory, "Queue");...

✅ How to speed up execution of BigInteger.Pow?

I have this: var result = BigInteger.Pow(1000, 10000000); I know this is a big number but generation of this number takes too much time. Is it possible to speed up?...

going into c#

so i realised that im not the best at frontend and even though im a beginner and am not the best programmer? i really enjoy and have a passion for c#, i guess what im getting at is, what should i do? where can i learn the ins and outs of c sharp and can i build a career off of it? im still in school if that gives any idea to how free i am during the week

"Building a C# Interface to Display Real-Time Data on macOS"

I need to build an interface using C# on a macOS laptop with an Apple Silicon chip. The goal is to create an interface that takes data and displays it, but I’m unsure how or where to begin. My background is in Java, but I now need to handle this project in C#. I’ve heard that .NET isn’t very well optimized for macOS, so I would really appreciate any guidance or suggestions on the best approach to move forward with this.

Need help inserting row to DB table from Ajax or unsure if supposed to be through the backend?

Hello, I was able to capture the PrimaryID1 to send to the backend using an ID1 to the dropdownlist, but I don't know how to send data to the server from the model without using an ID? https://paste.mod.gg/qnlljihvpcdx/0...

✅ Strings

StringBuilder newCrustacean = new StringBuilder(); newCrustacean.Append("fiddler crab"); Console.WriteLine(newCrustacean); newCrustacean.Remove(0,8); Console.WriteLine(newCrustacean);...

✅ Keyauth

keyauth doesn t work

Async issue

Hi! I'm trying to perform an http get request in a graphical element of the Eto library. Thing is, my whole program freezes until the response is received and I'm unsure why. ```csharp ...REST OF THE CODE... public class Body : StackLayout...

Is it necessary to setup validation constraints at the api level and database level?

I'm setting up a minimal api and just started to use FluentValidation. Should I also setup validation constraints at the database level as well?

Improving performance / caching

Hello, Im coming to an end with my database software. I filled the database with around 150 rows, but now I got the problem that performance is really trash with everything it does, even if it only does single row querys. So I thought maybe it´s possible to create a cache which stores all data once they are loaded which then is being used by all the other methods making a query. This is the code where all aircrafts are being collected, at the moment the data is loaded asynchron to not block the UI. How can I build such a cache with is used by every method?...