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
  • НаукаНаука

Комментарии • 37

  • @SubhamK108
    @SubhamK108 3 года назад +1

    Great Feature 👌
    This will be really helpful!

  • @Somfic
    @Somfic 3 года назад

    great job guys!

  • @Dimich1993
    @Dimich1993 3 года назад

    This is good stuff! Like TypeScript

  • @Shiro99King
    @Shiro99King 3 года назад

    Thanks for this tip

  • @geojthachankary8505
    @geojthachankary8505 3 года назад +1

    Will we get a compile time error if we supply a null in the constructor parameter while instantiating?

    • @victor1882
      @victor1882 3 года назад +2

      No, this feature only changes the code analysis and hinting, there is no change in runtime whatsoever

    • @SergeyLitvinovUA
      @SergeyLitvinovUA 3 года назад +1

      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

  • @Rocknmyself
    @Rocknmyself 3 года назад +2

    Hello,
    And what happens if we pass null for QuestionText in the constructor ?

  • @positronalpha
    @positronalpha 3 года назад +2

    New feature? Everything is relative :). Good stuff though.

  • @ajaykomireddy
    @ajaykomireddy 3 года назад

    how he is getting those shortcuts to get the code ? For instance he typed loop and I guess he is hitting tab ..

  • @rockymarquiss8327
    @rockymarquiss8327 3 года назад

    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.

  • @roboto1276
    @roboto1276 3 года назад

    I couldn't understand what the new feature is. i used that stuff many time

    • @Special1122
      @Special1122 Год назад

      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.

  • @earth20010
    @earth20010 3 года назад

    why are they using visual studio code instead of visual studio?

    • @vovcheable
      @vovcheable 3 года назад

      because they are using Mac

    • @brawnyvenky9584
      @brawnyvenky9584 3 года назад

      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.

  • @PraveenGandhi-Chennai
    @PraveenGandhi-Chennai 3 года назад +1

    from Kotlin?

  • @victorchisomnwisu9776
    @victorchisomnwisu9776 3 года назад

    wishing you did ??

  • @wiepcorbier
    @wiepcorbier 3 года назад

    You know what....

  •  3 года назад +1

    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);
    }
    }
    }

  • @timeless-sg
    @timeless-sg 2 года назад +1

    hmmm, I actually don't like it too much.

  • @dunks184wolf
    @dunks184wolf 3 года назад

    Do these videos remind anyone else of infomercials? They're too rehearsed but somehow also badly adlibed.

  • @adodrndar3891
    @adodrndar3891 3 года назад +1

    You didn't run the program, so that we could see that it actually works 😅

    • @obinator9065
      @obinator9065 3 года назад +10

      This ain’t JavaScript y’know

  • @ozsvartkaroly
    @ozsvartkaroly Год назад +2

    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.

  • @fass3686
    @fass3686 2 года назад

    this was not really helpful as a new learner

  • @AravindhKumar007
    @AravindhKumar007 3 года назад +6

    From my point of view, looks unnecessary and leaving the reference type as it's currently should be just fine.

    • @jonb8869
      @jonb8869 3 месяца назад +1

      After 2 years what do you think about this feature now?

    • @AravindhKumar007
      @AravindhKumar007 3 месяца назад

      @@jonb8869 I'm now a fan of this feature, it's well polished now 😅

    • @jonb8869
      @jonb8869 3 месяца назад

      @@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.

    • @AravindhKumar007
      @AravindhKumar007 3 месяца назад

      @@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.

    • @jonb8869
      @jonb8869 2 месяца назад

      @@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.