C
C#2y ago
OptoCloud

Safe to ignore non-null value on exit contructor? (disabling warning)

Can I safely add this as a ignore? I don't really know how I would fix this otherwise
5 Replies
Thinker
Thinker2y ago
You can write = null!; after the { get; set; } and that will force the compiler to shut up. And yes for EF you can safely ignore it as EF will set that property before you can access it, but the compiler can't know that.
OptoCloud
OptoCloud2y ago
im guessing adding a prabma is also fine?
Thinker
Thinker2y ago
yep You could also do #nullable disable at the top of the file
Angius
Angius2y ago
And when C# 11 arrives, required properties will be the solution to this issue
OptoCloud
OptoCloud2y ago
Im already using it :) Forces me to initialize that property when i construct the type
Want results from more Discord servers?
Add your server
More Posts
How should I start learninghi everybody I started learning c#, going through basics and want to ask those who in industry alreaCreating an instance of a class using DI [Answered]This is purely just out of curiosity. If you have a class which takes some arguments in its ctor andIs there any benefit to write a Property with a private variable ?Why: ```cs private int myVar; public int MyVar { get => myVar; set => myVar = value; } ``` may be beHow add analyzer for suggesting to add missing parameters or removing them?Soo I have analyzer which checks if parameter type is proper soo then I need to make codefix which j[ASP.NET] B-Logic Services, ValidationI am using anemic models, therefore I want to implement Business Logic Services. And the questions Optimizing some string manipulationI want to both substring an input string at the last occurrence of `'/'` and normalize it into *onlyRight way to use Interfaces in Large Scale Blazor Server Web ApplicationsHello there, iam currently working on a <see title> app for something iam not allowed to leak now iaUsing dependency injection for internal classes inside a libraryI'm making a library, where I feel like it would be useful to be able to use Microsoft's dependency System.InvalidOperationException The operation is not allowed on non-connected socketsi have client and server, client creates and connects tcp client to server tcp listener, client tcp HttpClient only working in Main but not in another Class? [Answered]I'm currently following a c# json tutorial and trying to put this code into it's own class so I can