I am a fairly advanced C#/C++ Software Engineer and I really enjoy your teaching style. You teach like you are speaking to a beginner and you are very professional, flexible and articulate. Plus I do not feel like I am being talked down to like some of the other you tube channels. Thanks again for a great video!
is there any chance to get a job and code with vsCode instead of Visual Studio? I'm a self-student, learning C#, and I don't really like using Ide. Cause of that, I'm gonna change the language I learning. (I know it sounds quite silly). What environment do you use?
@@stefano_schmidt do you and however you want to approach programming that is how you will ultimately approach it, but imo - I advise against this mentality because if/when you do get a job, your employer may very well require you to use a certain set of technologies that you have no say in (including frameworks, languages, 3rd party services, and IDEs and SDKs, and potentially even operating systems). Some companies are relaxed on this while others are not, and etc… although it is a “to each his own” sort of thing, I highly recommend being as technology-agnostic as possible when learning and becoming a developer, and by that I mean you should be able to get down with whatever technology or tech-related task there is to accomplish an outcome… remember, software development is about problem solving, not about coding… code is merely the facilitation of the problem’s solution, not the fundamental activity for which you are necessarily employed. There is a famous saying in Russia about this “for a bad dancer, even his balls get in the way”.
To be honest at first I was like why should I watch 1 hour video on NULL but at last I am glad I did, cos it was insightful and it bring clarity to the subject. Thank you Tim.
This is awesome Tim! Big help for my migration to .Net6. I’ve been seeing a lot of null-related warnings and this answers a lot (if not all) of my questions. Thank you very much!!
Thanks for your valuable video . i was recently started working on .Net 6 C# i came across these warning which were new to me. i did search and use only ? and ! operators. now i can do more and with confidence after this. Thanks once again.
Great video! Refactored a lot of my actual project with ??= and the null forgiving operator. Can't wait for the next sale on your website I will buy a lot of courses.
Didn't know I can watch a video about nothing for an hour xD! Was wondering what they did with the IDE because all these null warnings were driving me crazy, thanks for a very well explanation and making better coders of us all!
Great Video, as Always! It is targeted at beginners, so for me it was a bit long and I skipped a lot. A shorter viodeo, just on the feaatures that are not in previous versions would have been better for me. I know you primarly target beginners, so this goes into a lot of detail they may actually need to knw. Agaain... Great Video... keep up the good work!
Im slowly getting into c# in the next months and years(all im good at right now is PS). I will probably dig through alot of your videos, thank you alot for the effort and time you put into this!! It is indeed great times when it comes to soaking up knowledge and learning when there is a will! Thanks again, you rock!
Hi Tim! Thanks for the video - I have a question about one detail. Is there any guideline for using "var" vs "new()", e.g.: PersonModel user = new(); vs var user = new PersonModel(); I'm sure it's opinion-based, and there's no real right or wrong here, but is there any way we could organize it in our heads? The fact that they're so close in purpose (conciseness) makes it hard to choose... Also, in conext of the video, what do you think about ArgumentNullException.ThrowIfNull(user);?
As you said, this is an opinion but I prefer PersonModel user = new() as opposed to using var. The reason why is because code is meant to be read by humans. Seeing what the type is in front is what we are used to in most cases. It also easily communicates what we are making. That's just my thoughts, though. As for the ThrowIfNull, that's a good call in some circumstances. Just make sure you can't handle the error directly instead.
Thank you Tim! Your videos are great and really helpful. I'm learning a lot from them. I'm not a software engineer nor do I work as such. I'm actually a sales rep. I wish you had posted this before last weekend. I started migrating one of my .net framework apps to net 6 on Saturday, and a lot of these warnings started to poppingup here and there. Actualy, everywhere. I've started changing some of my classes to get rid of these warnings, but still have a long way to go. So, a little bit late, but this video comes at the right time to help me out. Again, thank you very much Tim.
Great video Tim! I wish this (detailed explanation on Nulls) was included in your complete C# Masterclass. I find it frustrating bc I have to go through the Masterclass and then find YT videos to get more info on a topic (I know your classes teach in layers and not all at once). Maybe add links in your paid videos (in each chapter) which point to your free YT videos? Reagardless keep up the good work!
I hear you, but the C# Mastercourse isn't about providing every single topic in full depth. In fact, there are a lot of places that you should go deeper. The purpose of the C# Mastercourse is to get you from knowing nothing (or wherever you are starting) to having a firm foundation in C# that you can both get a job with and also build upon to grow as a developer. There will always be more topics to learn.
Special thanks for explaining about conditional operator! Never used it before and couldn't find answer with uncomplicated requests like "What means ? in .NET/C#?" just like you said😵
At the end of this video, you give an example of getting a value from a database and make the comment that the value from the database would not be null. Could it be though? From my limited understanding, some fields in a database can be null depending on the design. Correct? If so, could I use this to check for that condition?
I believe in that specific case, the database column was marked as not null. But yes, you are correct that database values can be null if the design allows it to be. In that case, you would need to check for the null condition before using the property.
That null forgiving operator is more trouble than it's worth IMHO, I'll never use it. However, having recently started a new project in net 7, the extra null warnings and suggestions are massively improving my code and making me think about the design in ways I wasn't doing before. The resulting code is clearly better and more resilient, huge improvement from MS in that area.
Cool recap! 34:50 I mostly use it to set default values, especially in the builder pattern so your constructor never gets a null reference. So, if my builder has ConnectingWith(IClient client) but I don't specify it in the Build method I assign the client attribute as _client ??= new DefaultClient() or similar. 50:20 And about Nullable maybe you could have mentioned that Nullable is equal to type? for primitive types without having to dive into T. We have some very old code that uses Nullable and which will hopefully be updated eventually. Personally I dislike the ! operator, it's kind of contradictory saying "This variable could be null but here it will never be". I also kind of dislike the fact that by the time you leave the constructor every attribute must be initialized, it asks me to initialize every attribute in a builder at the constructor even if the end user (or I) will override them before using them in the Build() method. Thankfully they removed the !! operator from the NET 7 / C# 11 specs too.
Hello tim! I have a question about the elvis operator ?. (null conditional operator) and null forgiving operator !. Are the following statements the same? Console.WriteLine(person?.Name); Console.WriteLine(person!.Name);
No. The first one says "if person is not null, get the Name property on it, but if person is null, don't do anything." (so it will print a blank line) The second one says "I'm sure the person object is not null so don't warn me that it might be null." (if it is null, it will throw an exception)
Thanks for this video. Only 22 minutes in, hoping to get some claity on how to work with this because I am not a massive fan of doing null checks everywhere. For he most part I'd rather expect it to not be null and fine, throw me an exception if it happens to be and I'll gladly catch that and see what went on. The only good reason to do a null check is if under normal circumstances something could be null AND you can continue, which is likely what you'd want to do. I really don't want to be checking for null and throwing an exception of any kind...
The issue they are working to address is that unexpected null values can cause major problems in applications. In most cases, it is better to catch the issue and address it rather than just letting it crash the application. At the very least, you can log the issue before letting it crash.
What about assigning default to the non-nullable reference types? For example, public string Name {get; set;} = default!; Would this still be considered a non-nullable reference type?
The default value is still null for a string. So setting it to default would be null. Using the null-forgiving operator would just be lying to the compiler.
A reference type is expected to be null but now we have to tell that the compiler? Why should I tell that the compiler, I know that null is to be expected out of a reference type and I write my code around that? Sounds very strange to me, maybe I am confusing myself here.
It is about expectations (assumptions) in your code. By marking an object as nullable, you are saying "I'm ok with this being null sometimes". The compiler will then make sure that you have the appropriate null checks everywhere that you use that object. If you forget a place, the compiler will warn you about it. If you don't mark it as nullable, the compiler will assume that you are expecting it to be not null everywhere. It will then check to be sure that the object always has a value. If there is a place where it might not have a value, it will warn you. Null reference errors are a big problem in applications. This system allows you to more easily check for those issues at design time.
That's not the right solution. Here you are setting the value of the property to null and then telling the compiler it is not actually null. If the DbSet can be null, make it nullable: DbSet? Customers { get; set; }
Great video Tim! The challenge I run into is that when working on a front-end client, I sometimes get null values from a back-end API, including for a boolean property. On the back-end they use a NoSQL which is fine with null values for any property. But on the front end I have checkboxes on the UI which require either a true or false. I'm going to give coalesing a try.
Yep, that sounds like the right solution. Although, it would be good to clean up your front-end where those values are generated so that it properly gives you all of the required values.
@ghost mall thanks Ghost. Yup I've been using a view model to handle the nulls for the bool items coming from the API and converting them to false. But I'm going to try the suggestion you provided.
@@IAmTimCorey Thanks Tim. The initial values come from a third party, then to our back-end. They allow for null values, where we cannot. I really liked the 'coalesing' portion of the video, since it seems much more streamlined than the view model method I've been using.
As per reference type logic, string ab = "ABV"; string cv = ab; ab = "NEW ab"; Console.WriteLine(ab); Console.WriteLine(cv); Expected O/P: NEW ab NEW ab Actual O/P: NEW ab ABV
The "In-line If statement is called Ternary operator".. and yes.. dealing with nulls when you have LOTS of Models to work with dababases.. it CAN get very painfull!.. i've seen this issue dealed like: public int Id { get; set; } public string FirstName { get; set; } = null!; public string LastName { get; set; } = null!;
I dont like the forgiving operator. The entire point of these changes is to make you aware of null values and this operator just says: ignore the warnings.
I am a fairly advanced C#/C++ Software Engineer and I really enjoy your teaching style. You teach like you are speaking to a beginner and you are very professional, flexible and articulate. Plus I do not feel like I am being talked down to like some of the other you tube channels. Thanks again for a great video!
You're very welcome!
That’s the best way of teaching. That’s how I love to do it.
is there any chance to get a job and code with vsCode instead of Visual Studio? I'm a self-student, learning C#, and I don't really like using Ide. Cause of that, I'm gonna change the language I learning. (I know it sounds quite silly). What environment do you use?
@@stefano_schmidt do you and however you want to approach programming that is how you will ultimately approach it, but imo - I advise against this mentality because if/when you do get a job, your employer may very well require you to use a certain set of technologies that you have no say in (including frameworks, languages, 3rd party services, and IDEs and SDKs, and potentially even operating systems). Some companies are relaxed on this while others are not, and etc… although it is a “to each his own” sort of thing, I highly recommend being as technology-agnostic as possible when learning and becoming a developer, and by that I mean you should be able to get down with whatever technology or tech-related task there is to accomplish an outcome… remember, software development is about problem solving, not about coding… code is merely the facilitation of the problem’s solution, not the fundamental activity for which you are necessarily employed. There is a famous saying in Russia about this “for a bad dancer, even his balls get in the way”.
To be honest at first I was like why should I watch 1 hour video on NULL but at last I am glad I did, cos it was insightful and it bring clarity to the subject. Thank you Tim.
I am glad it was so helpful.
This is awesome Tim! Big help for my migration to .Net6. I’ve been seeing a lot of null-related warnings and this answers a lot (if not all) of my questions. Thank you very much!!
I am glad it was so helpful.
Everything anyone would want to know about null in C# 6+ at one place, thank you so much for the great content :)
You are welcome.
Learned from you something new though beeing a 30 years professional just coming back to C# after a while. Your stye is awesome. Thank you!
You are welcome.
After watching this video, for me "What are nullables?" CHAPTER has been CLOSED. Thank you Mr. Tim Corey.👍
Excellent!
Good tutorial on nullable things in C#! Will recommend to my team migrating big project to .NET 6.
Thank you!
Thanks for your valuable video . i was recently started working on .Net 6 C# i came across these warning which were new to me. i did search and use only ? and ! operators. now i can do more and with confidence after this. Thanks once again.
You are welcome. I’m glad it was so helpful.
thanks man , this is really an all-in-one tutorial that I have been looking for!
You are welcome.
Love your videos as they are very comprehensive and very nicely explained. Thanks a lot.
You are welcome.
Great video! Refactored a lot of my actual project with ??= and the null forgiving operator. Can't wait for the next sale on your website I will buy a lot of courses.
I am glad it was so helpful.
Didn't know I can watch a video about nothing for an hour xD!
Was wondering what they did with the IDE because all these null warnings were driving me crazy, thanks for a very well explanation and making better coders of us all!
I am glad it was so helpful.
Great Video, as Always! It is targeted at beginners, so for me it was a bit long and I skipped a lot. A shorter viodeo, just on the feaatures that are not in previous versions would have been better for me. I know you primarly target beginners, so this goes into a lot of detail they may actually need to knw. Agaain... Great Video... keep up the good work!
Thanks!
Thanks!
Thank you!
Me: Is confused on a subject
Tim: Uploads a tutorial on that subject
I am glad it was so helpful.
Im slowly getting into c# in the next months and years(all im good at right now is PS). I will probably dig through alot of your videos, thank you alot for the effort and time you put into this!! It is indeed great times when it comes to soaking up knowledge and learning when there is a will! Thanks again, you rock!
You are welcome.
Thanks
Thank you!
Thanks for the video Tim - You are the best!
You are welcome.
Hi please make a tutorial full on c# basics in depth . I like your way of teaching style.
Perfect demonstration Tim. Thank You!
You are welcome.
Hi Tim! Thanks for the video - I have a question about one detail. Is there any guideline for using "var" vs "new()", e.g.:
PersonModel user = new();
vs
var user = new PersonModel();
I'm sure it's opinion-based, and there's no real right or wrong here, but is there any way we could organize it in our heads? The fact that they're so close in purpose (conciseness) makes it hard to choose...
Also, in conext of the video, what do you think about ArgumentNullException.ThrowIfNull(user);?
As you said, this is an opinion but I prefer PersonModel user = new() as opposed to using var. The reason why is because code is meant to be read by humans. Seeing what the type is in front is what we are used to in most cases. It also easily communicates what we are making. That's just my thoughts, though. As for the ThrowIfNull, that's a good call in some circumstances. Just make sure you can't handle the error directly instead.
@@IAmTimCorey Thank you for the great remarks!
Thank you Tim! Your videos are great and really helpful. I'm learning a lot from them. I'm not a software engineer nor do I work as such. I'm actually a sales rep. I wish you had posted this before last weekend. I started migrating one of my .net framework apps to net 6 on Saturday, and a lot of these warnings started to poppingup here and there. Actualy, everywhere. I've started changing some of my classes to get rid of these warnings, but still have a long way to go. So, a little bit late, but this video comes at the right time to help me out. Again, thank you very much Tim.
I am glad it will be helpful.
Great video Tim! I wish this (detailed explanation on Nulls) was included in your complete C# Masterclass. I find it frustrating bc I have to go through the Masterclass and then find YT videos to get more info on a topic (I know your classes teach in layers and not all at once). Maybe add links in your paid videos (in each chapter) which point to your free YT videos? Reagardless keep up the good work!
I hear you, but the C# Mastercourse isn't about providing every single topic in full depth. In fact, there are a lot of places that you should go deeper. The purpose of the C# Mastercourse is to get you from knowing nothing (or wherever you are starting) to having a firm foundation in C# that you can both get a job with and also build upon to grow as a developer. There will always be more topics to learn.
Very good episode with lot of useful staff. Thanks a lot sir :)
You are welcome.
Thank you for making this video!
You are welcome.
Another great one.
Tnx, Tim
You are welcome.
Know all this stuff but ??= was a surprise, thanks for the thorough handling.
You are welcome.
Thanks Tim - Just what I needed!
You are welcome.
Special thanks for explaining about conditional operator! Never used it before and couldn't find answer with uncomplicated requests like "What means ? in .NET/C#?" just like you said😵
You are welcome.
Thanks for making this video.
You are welcome.
At the end of this video, you give an example of getting a value from a database and make the comment that the value from the database would not be null. Could it be though? From my limited understanding, some fields in a database can be null depending on the design. Correct? If so, could I use this to check for that condition?
I believe in that specific case, the database column was marked as not null. But yes, you are correct that database values can be null if the design allows it to be. In that case, you would need to check for the null condition before using the property.
Thank you for the explanation!
You are welcome.
Great video. Loved it.
Thank you!
Thanks I was confused about the nullable option and the operators
You are welcome.
That null forgiving operator is more trouble than it's worth IMHO, I'll never use it. However, having recently started a new project in net 7, the extra null warnings and suggestions are massively improving my code and making me think about the design in ways I wasn't doing before. The resulting code is clearly better and more resilient, huge improvement from MS in that area.
I'm glad you are getting value out of it.
Thanks a lot tim,
Really helpful...
You are welcome!
how to create global field here to use by other methods and also how to create DI in a console app for the new Net Core?
Awesome content, thank you
You are welcome.
Excellent explanations. Would love to see a follow-up to this covering "default" values.
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Cool recap!
34:50 I mostly use it to set default values, especially in the builder pattern so your constructor never gets a null reference. So, if my builder has ConnectingWith(IClient client) but I don't specify it in the Build method I assign the client attribute as _client ??= new DefaultClient() or similar.
50:20 And about Nullable maybe you could have mentioned that Nullable is equal to type? for primitive types without having to dive into T. We have some very old code that uses Nullable and which will hopefully be updated eventually.
Personally I dislike the ! operator, it's kind of contradictory saying "This variable could be null but here it will never be". I also kind of dislike the fact that by the time you leave the constructor every attribute must be initialized, it asks me to initialize every attribute in a builder at the constructor even if the end user (or I) will override them before using them in the Build() method. Thankfully they removed the !! operator from the NET 7 / C# 11 specs too.
I'm glad you enjoyed it.
Hello tim!
I have a question about the elvis operator ?. (null conditional operator) and null forgiving operator !.
Are the following statements the same?
Console.WriteLine(person?.Name);
Console.WriteLine(person!.Name);
No. The first one says "if person is not null, get the Name property on it, but if person is null, don't do anything." (so it will print a blank line) The second one says "I'm sure the person object is not null so don't warn me that it might be null." (if it is null, it will throw an exception)
Great lesson, thank you!
You are welcome.
Thanks for this video. Only 22 minutes in, hoping to get some claity on how to work with this because I am not a massive fan of doing null checks everywhere. For he most part I'd rather expect it to not be null and fine, throw me an exception if it happens to be and I'll gladly catch that and see what went on. The only good reason to do a null check is if under normal circumstances something could be null AND you can continue, which is likely what you'd want to do. I really don't want to be checking for null and throwing an exception of any kind...
The issue they are working to address is that unexpected null values can cause major problems in applications. In most cases, it is better to catch the issue and address it rather than just letting it crash the application. At the very least, you can log the issue before letting it crash.
Thank you so much!!!
You are welcome.
What about assigning default to the non-nullable reference types? For example, public string Name {get; set;} = default!; Would this still be considered a non-nullable reference type?
The default value is still null for a string. So setting it to default would be null. Using the null-forgiving operator would just be lying to the compiler.
A reference type is expected to be null but now we have to tell that the compiler? Why should I tell that the compiler, I know that null is to be expected out of a reference type and I write my code around that? Sounds very strange to me, maybe I am confusing myself here.
It is about expectations (assumptions) in your code. By marking an object as nullable, you are saying "I'm ok with this being null sometimes". The compiler will then make sure that you have the appropriate null checks everywhere that you use that object. If you forget a place, the compiler will warn you about it. If you don't mark it as nullable, the compiler will assume that you are expecting it to be not null everywhere. It will then check to be sure that the object always has a value. If there is a place where it might not have a value, it will warn you. Null reference errors are a big problem in applications. This system allows you to more easily check for those issues at design time.
@@IAmTimCorey Thanks for the clarification :)
very good , liked it . ... As allways!
Thank you!
Great info😊😊😊
Thanks!
Can you explain the nullable generic list
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Thanks Tim!
In ef core I often use:
public DbSet Customers { get; set; } = null!;
to avoid green underline, but may somebody have some other clue?
That's not the right solution. Here you are setting the value of the property to null and then telling the compiler it is not actually null. If the DbSet can be null, make it nullable: DbSet? Customers { get; set; }
A solution I found that works for me is: public DbSet Authors => Set();
Not sure what the source was but it works quite well
Hello Tim can you please please make a video on signalR?
I already did. Here is part 1: th-cam.com/video/RaXx_f3bIRU/w-d-xo.html and here is part 2: th-cam.com/video/-JzWg-Kwu7g/w-d-xo.html
Great video Tim! The challenge I run into is that when working on a front-end client, I sometimes get null values from a back-end API, including for a boolean property. On the back-end they use a NoSQL which is fine with null values for any property. But on the front end I have checkboxes on the UI which require either a true or false. I'm going to give coalesing a try.
Yep, that sounds like the right solution. Although, it would be good to clean up your front-end where those values are generated so that it properly gives you all of the required values.
@ghost mall thanks Ghost. Yup I've been using a view model to handle the nulls for the bool items coming from the API and converting them to false. But I'm going to try the suggestion you provided.
@@IAmTimCorey Thanks Tim. The initial values come from a third party, then to our back-end. They allow for null values, where we cannot. I really liked the 'coalesing' portion of the video, since it seems much more streamlined than the view model method I've been using.
As per reference type logic,
string ab = "ABV";
string cv = ab;
ab = "NEW ab";
Console.WriteLine(ab);
Console.WriteLine(cv);
Expected O/P:
NEW ab
NEW ab
Actual O/P:
NEW ab
ABV
The "In-line If statement is called Ternary operator".. and yes.. dealing with nulls when you have LOTS of Models to work with dababases.. it CAN get very painfull!.. i've seen this issue dealed like:
public int Id { get; set; }
public string FirstName { get; set; } = null!;
public string LastName { get; set; } = null!;
I'm not a huge fan of lying to the compiler, but I definitely get it. I would rather see the nullable disabled for that model.
@@IAmTimCorey indeed! Thanks to this video I changed all those = null!; to just a #nullable disabled for those entities. 👍
One day when i make it i buy you the best steak in town.
I am glad it was helpful.
string[] explanations = {"first", "second", "third"};
string? me = explanations.Perfection(every, single, one);
Thank you!
I use a ??= as a lazy loader for properties.
private int? _i;
public int i {get { return _i ??= doSomeCalc();}}
Ah, that's a good option.
I dont like the forgiving operator. The entire point of these changes is to make you aware of null values and this operator just says: ignore the warnings.
The compiler doesn’t always know best. That’s what it is for.
Thank you... Pleas i want 1or 2 vedios about identity server 4
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Before the video: ??, ?, null!;
after the video things i know now (s is not null), ??= nice
I am glad you learned something.