C# Language Highlights: String Interpolation

Поделиться
HTML-код
  • Опубликовано: 6 сен 2024
  • In this video, James ( / jamesmontemagno ) and Maira ( / mairacw ) explain how string interpolation works in C#
    🏫 Free self-guided learning for C# on Microsoft Learn: aka.ms/learn/c...
    String Interpolation (C# reference)
    docs.microsoft...
    String Interpoloation in C#
    docs.microsoft...
    String Interpolation interactive tutorial
    docs.microsoft...
    Take your first steps with C#
    docs.microsoft...
    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

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

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

    I had seen basic examples of string Interpolation, but didn't know all of its capabilities. Thanks.

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

    If they could replace their online examples with these pair, i might actually learn something! Thank you for showing this neat trick.

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

    I prefer C#'s implementation of this above JavaScript's use of the `` and the ${} within the string itself, just feels more consistent and natural. Both save so much time though, great features.
    Edit: JavaScript feature not TypeScript.

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

      That's a JavaScript feature, not a TypeScript feature...

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

      @@thethreeheadedmonkey That's right, have updated - thanks.

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

    I like how with java all we need to do to manipulate strings like this is a "+" symbol

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

    Yes, I use it a lot.. BUT..
    What about all these boxing and unboxing going under the hood ?
    How does it impact on performance and/or memory usage ?
    [please, answer me.. 🙏]

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

      Do some perf tests

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

      Exactly. I wander the results of the tests that have been done so far. I'm sure there ought to be a lot of them. And I am also sure *Microsoft* (and the *dotNET* team) must have a direct, clear and official position on the matter.
      Besides, if I were to test it by myself I wouldn't have posted such questions, right ? And even if I do (or have done), I really would appreciate to know what the creators of such feature have to say about these issues.

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

    dope!

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

    It is amazing how many devs are not using this feature ...

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

      I agree, the code looks so bad n ugly

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

      $"Why aren't they using {thisFeature}?"
      I use it extensively for code generation

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

      @@klogdogger But they are

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

    Noice

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

    regarding this "cool feature", "logic" in string interpolation, I would reject PR with code like this so fast you have no idea :) its quite obvious that you can run any statement in that returns something there... but for god sake you could wrap it in some method or calculate its value earlier? I'm sure that some part of an audience just started to program and I'm sure they dont see that its wrong to write code like this. you learn it quickly, if you see a wall of interpolated text in you editor and you did not write it and you dont have any tests for it, and you have to do a quick fix :) I know your point of view you are just showing features as is :) bla bla bla :) its bad code, period.
    var s = $"this is a test of {(data.SomeValue || DateTime.IsLeapYear(DateTime.Now.Year) ? "bla" : (data.OtherValue && DateTime.Now.Day % 2 == 0) ? (data.Foo || data.Bar && !data.SomeValue) ? "foo" : "bar" : "cool feature")} so easy to read";
    add 10 more interpolations in this string like this and you will jump out of a window after you open file with this code :)