C
C#

help

Don’t understand nullable reference types

PPlayboi1710/19/2022
PPlayboi1710/19/2022
Documentation says that non-nullable reference types “must be initialized to a non-null value” and “compiler issues a warning when code assigns maybe-null” Yet in the picture which is from a dotnet entity framework video, they just set firstname and lastname, non-nullable reference types, to null How? It says you can’t initialize to null value
TThinker10/19/2022
null! essentially forces the compiler to shut up about nullability warning. You can set non-nullable reference types to null just fine, it's just the compiler which will warn you about it. But if you say "shut up" to the compiler then it won't complain
PPlayboi1710/19/2022
Thank you. I dont see why you would want to lose the warnings? If you don’t want the warnings and can still set it to null, why not use a nullable reference type? So the “?” only affects compiler warnings and doesn’t affect the behavior of the variable?
TThinker10/19/2022
For reference types, yes Sometimes you have a situation (like with EF) where you don't have an initial value to set anything to, but you know for certain that the value won't be null when you actually access it. EF will set those values for you before you can properly access them
PPlayboi1710/19/2022
Answered before I could ask, are you saying it has a default constructor? If you don’t initialize firstname for example, will it just make it white space?
TThinker10/19/2022
Strings are by default null All reference types are by default null
PPlayboi1710/19/2022
But you said “EF will set those values for you before you can properly access them”. I’m talking in that scenario.
TThinker10/19/2022
I mean that when you access a model, EF with have initialized it already

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Get Environment Variables...I am trying to get the connection string for my Azure Tables with the following code. TabHow to find the implementation of Math. functionsI think i've heard mathematical functions of `System.Math` is implemented in external libraries writMaking concrete object classes```cs private void Initialize_NavigationItems() { var fooNavigationItem SignalR Get Client State From Another Service.Hello, I have a SignalR client, and a method in another service that get called by the client with aSetting the id of an object to property in a nested Object on creationHey devs, I have a little tricky one this time, which is possibly very simple to implement. so I havEF Core many-to-many relation errorThis is the error I am getting : And I don't really know how to fix it. These are my modals ```cshHow do I simulate the logs I keep?I have a data stream in a winframe interface. I keep these logs somewhere and when I press the simulHow do i publish an asp.net Core applicationI can't use `dotnet publish` as i use COM references, but i need a release build of my aspnetcore prInvalidCastException Specified cast is not valid.```cs public void DestroyCities() //102 { //103 foreach(GameObject go in transform) //10Camera Isnt Zooming Back OutSo, when the bullet is spawned, the camera zooms in to 55. Why when the FOV is = 55 doenst it zoom bHow to detect if my ASP.Core app is running from the ef-core tool in Design time?I'm running into a weird issue where the `dotnet ef` tool keeps trying to start up my web app, insteImported a package, but using statement isn't working?I'm trying to use MudBlazor for my .net 5 blazor application, and I have imported it. However the usSqlite EntityframeworkHi, what's the best choice here ? should i create my user with all the options in the same models foxamarin appso i got a task to make this simple app with no logic just the look and my problem is how can i alliStructuring SQL database to accommodate modelsI have the following models (simplified for demo): ``` public class Event { public int Id { get; How to version multiple self maintained dependent SDK packages pushed via azure pipeline?We have multiple components that have SDKs generated and pushed a private package repository during Remove list element```cs AddTabGroupChildren(Config.KpiSelection.TabHierarchy.TabBase); private void AddTabGroupChildreDeserializing Given Text File Into JSONGood evening, I've spent weeks trying to get the data out of this text file into a proper set of var.NETFramework 5.0 and 6.0 reference assemblies missing, but dotnet --list-sdks sees them [Answered]``` Project "/home/sparr/src/Harmony/git/Harmony/Harmony.csproj" (2) is building "/home/sparr/src/Hacant change text label inside events?why is scorelbl.Text red when I have label named like that in designer?