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
I had seen basic examples of string Interpolation, but didn't know all of its capabilities. Thanks.
If they could replace their online examples with these pair, i might actually learn something! Thank you for showing this neat trick.
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.
That's a JavaScript feature, not a TypeScript feature...
@@thethreeheadedmonkey That's right, have updated - thanks.
I like how with java all we need to do to manipulate strings like this is a "+" symbol
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.. 🙏]
Do some perf tests
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.
dope!
It is amazing how many devs are not using this feature ...
I agree, the code looks so bad n ugly
$"Why aren't they using {thisFeature}?"
I use it extensively for code generation
@@klogdogger But they are
Noice
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 :)