C#

C

C#

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

Join

help with project for school, the program keeps looping and doesn't stop adding "*"

```Console.WriteLine("how many lines do you need?"); int l; l = int.Parse(Console.ReadLine()); Console.WriteLine("how many columns do you need?"); int c;...

✅ Problem connecting entities on efcore

I'm new with blazor and efcore and i'm in trouble to connect 2 relation Error: ---> Npgsql.PostgresException (0x80004005): 23505: Duplicate key value violates unique constraint "PK_Blocks" Method:...

C# programming in Linux Mint

What is the best IDE to programm C# on Linux Mint?

✅ ASP.NET MVC and mapping correct views.

Im working on a project that's split in two: There's an API project built in ASP.NET WEB API - and the Frontend in ASP.NET MVC. Im trying to make it so when you log in and the TwoFactorEnabled in the MS Identity database is set to True then you'd be taken to a View called "Verify2FA", "TwoFactorAuth" There the User would be prompted to enter the 2FA code from their phones and clicking verify; If the Code is correct they get to move on to "Dashboard", "Admin"...

✅ DbContextOptionsBuilder.UseMongoDB is not referenced after use AspNetCore.HealthChecks.MongoDb

As above I recently added AspNetCore.HealthChecks.MongoDb to my project and the code below stop working ```cs builder.Services.AddDbContext<LightningLanesDbContext>((serviceProvider, opt) => { var databaseSettings = serviceProvider.GetRequiredService<IOptionsMonitor<DatabaseSettings>>().CurrentValue;...

Why ins't inlining working here?

Just doing an experiment. The following code are not inlined by the compiler: ```csharp class Program {...

✅ Is there a reason to still be using EventArgs and EventHandler<T> for events?

I see the usage of both aforementioned types in the msdocs for events. Even in new-ish blogs and packages, I see some people still using this approach. However, I fail to see a point to it. Event declarations can be of any delegate, like Action<T> or Func<T, T>. And EventArgs seems utterly pointless. So, I just want to make sure: Is this just an outdated convention? Or are there secret runtime benefits of doing events this way?...

Dealing with HTTPClient metrics

Hi, i currently working on httpclient metrics, goal is fair easy - i just want draw a chart which represents request to external dependency in time - i tried something like this -> sum by(server_address)(http_client_active_requests) But in my opinion data does'nt correspond with real traffic. What i make wrong? I collect metrics with multiple apps using prometheus
No description

Form Data Binding Issue in ASP.NET Core MVC - Dictionary Not Receiving Values

I’m encountering a problem in my ASP.NET Core MVC project when trying to bind form data from dynamically generated checkboxes and text inputs to a dictionary in my view model. Despite selecting checkboxes and entering values, the dictionary in my controller isn't receiving the expected values after form submission. I’m attaching my project files and database script so you can replicate the issue with my actual setup. The goal is to ensure that selected variant items (with checkboxes) and their associated prices are properly inserted into the tbl_product_variants_relation table. Here are the key areas:...

✅ how I can write like this?

idk what it called but I can use same logic writing in other language ```cs int a = 0; int b = 1; ...
No description

✅ could not be translated

Generally what solution do you use when you get the "could not be translated" error from ef core? I generally try to use a [NotMapped] property(it doesn't always work), but I saw that it is possible to create a procedure to translate a specific command

✅ Deserialize JSON back into custom object

Hey all, I have an ObservableCollection that I am using to store a list of tasks (A custom object "TaskItem" that is build like this. ```c#...

✅ ”base”

```cs public class Person { protected string ssn = "444-55-6666";...

✅ Change WPF element style depending on property value

Hey, trying to set the "disabled" color of a button in my little practice app. I have the button setup with a command binding so that unless something is selected in a datagrid, the button is disabled. I tried setting up a style trigger but assuming whatever is handling disabling the button automatically is not setting the "Disabled" property though. ...
No description

How to convert a whole json file to C# classes with Newtonsoft.Json?

Hello, I am curious if there is a way to convert a whole json File with Newtonsoft.Json to C# classes without knowing anything about the file. The code should be written in C#. I tried nearly every tutorial on YouTube and every Tutorial is about serializing or deserializing only one object at a time, and I looked over on some examples on Stack - Overflow and even Bing Chat gives me the same answer. I really need this for a Project I am building on, any example with the specific topic I was writing about earlier could help!
Thanks for help!...

✅ get set help

i dont understand the application of a get set method. are there any practical examples you can give?

VS hangs while typing

Curious if you guys had any ideas My machine at work is running VS When I type in the code editor, it's often several seconds before the editor catches up to what I typed and several seconds again before I get suggestions or the intellisense browser. ...

Does it make sense to two references (to database migration and data seeding) in the same using

I am totally new to this, so I rely on chatGPT a lot With the help of GPT I have wrote a code like this ```var app = builder.Build(); ...