C#

C

C#

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

Join

ValueType disposable scope

Is there a safe way to use a value type to manage a disposable "scope"? For example in this code, it should write "1" to the console, but it actually writes "2" because it creates a copy of scope1 and disposes it: ```cs private static int disposeCount = 0; public ref struct Scope(object myObject) {...

Help with clean architecture

I wondered how I could return the DTO without breaking anything. Here is the code from the service where I access the entity. ```cs public async Task<IReadOnlyList<Todo>> GetAllTodosAsync()...
No description

BindingFlags of System.Reflection

Can you please explain me the concept and importance of BindingFlags of System.Reflection? I have the read the MS documentation but still in doubt. Thanks...

✅ Career advice

Hello recently its been very hard for me to find a new job, as im thinking to switch job because of the very outdated techs that sre used in my current company. I have used .net/.net core for backend web apis, in fact currently im building another web api now, but most jobs require full stack(either angular or react), cloud computing(azure or aws) or devops, where im a beginner in frontend, cloud or devops id say. After i finish my current web api that im building, i plan to develop its frontend with react, try to host it on azure, and then get to azure devops. Its just that i dont know if thats the right path to take or if it could really help me with my current situation. If somebody has any suggestions or can help me with it please dm me. Thank you!...

✅ Importance of getters and setters

Hello, can someone explain the importance of getters and setters in programming please. I know with setters, we can check for conditions, like if age < 18, then do something but apart from that, why do we force devs to make use of setters/getters? ...

Inheritance and polymorphism

Hello, can someone clarify if my understanding of inheritance and polymorphism is correct please. From what I've understood, inheritance is a mechanism that allows one class (say dog class) to "inherit" the features of another class (say animal class for e.g). For instance, an animal may have a name, a sound which it makes and so does the dog if it inherits from animal. I know their is something that we call dependency injection, is this an application of inheritance?...

making source-generated files visible to copilot

does anyone know a way to do this? EmitCompilerGeneratedFiles will dump the files into obj/, but it seems like copilot's MCP tools won't read anything that's in .gitignore - so moving them elsewhere doesn't help either

✅ Passing subset of options when resolving instance with MS.DI (Working example with DryIoc)

@viceroypenguin Continuing the discussion we were having last night about moving away from DryIoc, I am currently using scope.Use(foo) when resolving instances at startup based on config and looking to simplify and just use MSDI. I created an example project to better illustrate how I'm currently wiring everything up https://github.com/ksladowski/device-registration-example...

✅ Working with abstract classes in a homework problem

So for this bit of homework I'm doing, im required to make it so that a player, a class that inherits abstract class gameobject, cannot go further than the reaches of the canvas. I'm not very good at abstract classes, but I had the idea to override the move methods as given in the abstract class so I could use them in the player class according to movement specification

async void

I have a 'void' return type method that needs to launch an async method. 1. I could use try-catch (I'm used to this approach usually, since the errors can be wrapped up) ```cs private async void SomeLegacyHandler()...

Setting up netcoredbg for NeoVim

I've been trying to setup a debugger for C# on my NeoVim but what I've done so far has not show any effect. I've already successfully setup debugging for C on this machine in the same exact way so I wonder why it is not working. This is my system: ...
No description

Help with home work

The goal is to change the direction of the square from x to y then y to x. I seem to not understand the logic(I DO NOT WANT THE ANSWER JUST HELP TO IT) ``` using UnityEngine; using UnityEngine.UIElements; ...

Presentation layer vs business layer vs data layer

Hello, can someone explain why we have things like presentation logic, business logic and data logicpls. I know that we need them because of principles like separation of concerns, but why do they matter, just for easier mantainability? Can someone confirm if the following is correct pls:...

✅ Is there any AspNetCore application demo to learn from ?

AspNetCore docs "fundamentals" parts are boring, i actually want to see how others making an AspNetCore web application. So is there any project demo like that?😋

.NET Best Practice on Architectural Design for a Multi-Solution Project

Hello everyone!! ^_^ I wanna mention that I've been a self-taught .NET developer for almost 10 years now, and I feel like my experience is slowly but surely paying off. A while ago, I decided to enable all analyzers across my solutions and treat warnings as errors in order to improve my code quality and ensure it follows .NET standards and best practices. However, after doing this, some parts of my codebase trigger certain warnings, including CA1515 warnings, which suggests that certain members should be marked internal rather than public....

syntax errors

it says there are syntax errors even tho im pretty sure there isnt any

Global variable that only exists during initial call + async continuations

Hey so in my app I have a transition from void to async. During the initial call to the async part (the synchronous part) and all continuations, I want to be able to set a global variable, and only for continuations that originate from that original call. This is so that I can associate different globals to the same async call. The void to async part also happens on my app's main thread, and continuations ofc only run on the main thread. Is there a way to do this?...

New C# dev struggling to configure for linux

Hey! I'm in a course for C# development right now, but I'm having some issues configuring my machine for development. I'm currently on Manjaro and I'm using Rider, but I'm attempting to get dotnet 6.0 and 9.0 installed on my machine (some of my course material/the repos I work from are older and target 6.0, but the coursework is for 9.0) -- I'm just having a bit of trouble getting everything configured as it should be and I'd appreciate a guiding hand in getting everything set up properly for development on linux. Thanks!!...