C# Language Highlights: Nullable Reference Types
HTML-код
- Опубликовано: 10 июн 2021
- Learn about the benefits of Nullable Reference types from Leslie / lyrichardson01 and Matt / codemillmatt in this short video.
🏫 Free self-guided learning for C# on Microsoft Learn: aka.ms/learn/csharp
Nullable Reference types
docs.microsoft.com/dotnet/csh...
Understanding Nullable Reference Types
docs.microsoft.com/dotnet/csh...
First steps with C#
docs.microsoft.com/learn/path...
Get your questions answered on the Microsoft Q&A for .NET - aka.ms/dotnet-qa
Learn .NET with free self-guided learning from Microsoft Learn: aka.ms/learndotnet
#DotNet #CSharp Наука
Great Feature 👌
This will be really helpful!
great job guys!
This is good stuff! Like TypeScript
Thanks for this tip
Will we get a compile time error if we supply a null in the constructor parameter while instantiating?
No, this feature only changes the code analysis and hinting, there is no change in runtime whatsoever
It will give you warning that you pass null value to constructor, and you can also enable to treat warnings as errors and then it would display compilation error as result
Hello,
And what happens if we pass null for QuestionText in the constructor ?
i have same question. is it possible?
@@sharepointrss7178 your computer will blow up
New feature? Everything is relative :). Good stuff though.
how he is getting those shortcuts to get the code ? For instance he typed loop and I guess he is hitting tab ..
They are code snippets.
The code is popped in so quick it's easy to miss exactly what was done - it took a second to see how the hint on the second question was put in.
I couldn't understand what the new feature is. i used that stuff many time
yes you could do it before but what if you forgot to set some property? enabling nullable reference types means static and compile-time analysis and you get warning if you declared something as non-nullable but forget to set it's value at constructor.
why are they using visual studio code instead of visual studio?
because they are using Mac
since dotnet has become open source and we can run csproj using dotnet run command from commandline, we can either use VSCode or visual studio. But enterprise coding Visual Studio is more preferred.
from Kotlin?
My thoughts exactly 🤣
wishing you did ??
You know what....
namespace Test
{
public class SurveyQuestion {
public string Question { get; init; }
public string Hint { get; init; }
public SurveyQuestion(string question, string hint="") => (Question, Hint) = (question, hint);
public override string ToString() {
if (Hint.Length > 0) return $"{Question} (Hint: {Hint})";
return Question;
}
}
class Program
{
static void Main(string[] args)
{
var surveyQuestions = new List();
surveyQuestions.AddRange(new [] {
new SurveyQuestion("What's your fave IDE ?"),
new SurveyQuestion("What is the best programming language ?","You are looking at it")
});
foreach (var q in surveyQuestions) Console.WriteLine(q);
}
}
}
hmmm, I actually don't like it too much.
Do these videos remind anyone else of infomercials? They're too rehearsed but somehow also badly adlibed.
You didn't run the program, so that we could see that it actually works 😅
This ain’t JavaScript y’know
I don't find this video useful, the style is too beginner-like, however the whole concept of nullable reference types is not really beginner-level.
The result is this shallow video that isn't really useful.
this was not really helpful as a new learner
From my point of view, looks unnecessary and leaving the reference type as it's currently should be just fine.
After 2 years what do you think about this feature now?
@@jonb8869 I'm now a fan of this feature, it's well polished now 😅
@@AravindhKumar007 Any pitfalls you've ran into? I know the feature can change how query params are interpreted and I dislike how easy it is to "swallow" exceptions.
We're thinking of migrating to it, I like the explicitness even if it requires a bit more work.
@@jonb8869 you'll still have to rely on model validations including the Required validation because the empty strings will be allowed by default. This was a quirk but still an acceptable one. Otherwise it's all good.
If used properly, you can avoid almost all the null reference exceptions in runtime.
@@AravindhKumar007 I've never found null ref exceptions to be a problem. I like to know when there are problems with the code.
What I do like about this feature is making the use of null explicit.