C# 11's NEW elegant string conversion

preview_player
Показать описание

Hello everybody I'm Nick and in this video I will introduce you to a feature coming in C# 11 called UTF-8 String Literals. If you are dealing with UTF-8 strings a lot, this feature will simplify your code significantly and make it way more efficient.

Don't forget to comment, like and subscribe :)

Social Media:

#csharp #dotnet #utf8
Рекомендации по теме
Комментарии
Автор

Your videos are great. Even for a hobbyist coder, you make C# news interesting!

Salmonman
Автор

This is really useful when making an interpreter for ASCII based protocols which use BCD for datatypes.
For example communicating with serial devices over RS232 & RS485. (Yes I'm old school. The automation industries is slow to adapt Ethernet based systems).
Avoiding the Encding.ASCII.GetBytes() is really nice.

McTopaz
Автор

Well done Nick, been watching since around 30k subs, awesome content, I learn a lot, thanks

Radictor
Автор

Congratulations, Nick! (and nice video as always). Keep the content coming; I'll be watching every single masterpiece you produce.

Quick question: I know your primary focus are APIs and Microservices but I wonder if you are planing to make some UI related stuff for Desktop like WPF and/or MAUI with WinUI (maybe consuming the APIs?).

Cheers!

jonatancordoba
Автор

I think this is a great feature and thanks to your channel I'm up-to-date.

muhamedkarajic
Автор

Just for clarity, you can use Encoding with span just get the count with GetByteCount allocate a span in stack and then call GetBytes passing both string as input and span as destination

diadetediotedio
Автор

Congrats Nick! Your videos are awesome, and you deserve all of the support and recognition that you are getting! As to this video... we definitely have a lot of use cases for this in our product!

brianm
Автор

You are really one of the best (esp. with Benchmarks you are King)

lollo
Автор

Great feature. I am going to use it all the time for parsing HTML.

SuperHddf
Автор

A lot of resources being dumped into C#'s performance that last few years. That is great as it will be used in more areas. Efficiency is what put C/C++ everywhere.

FunWithBits
Автор

Could you make a video on the most common pre-implemented Exception types and best practices of when and how much to throw them? It seems to be such a trivial topic, but the amount is overwhelming and the differences are quite subtle, ie ArgumentNullException vs NullReferenceException or NotImplementedException vs NotSupportedException? For which and when is it a good practise to throw (if ever) one of these and when should we throw custom Exceptions?

hanspetervollhorst
Автор

It's a nice feature to have. I would like to have an opportunity to have an ability to make such optimized conversions to other encoding too. Seldomly I need to work with other encondings

antonmartyniuk
Автор

i would love some kind of explicitity in there. This is just confusing without context

thatKurtis
Автор

That implicit conversion performance boost really justifies any aspect of the syntax that might not be to everyone's taste. Batched ETL processes using text files can benefit greatly from this feature for sure!

danilonotsys
Автор

Really cool feature! It needs that suffix though. This feature would be used every day where I work.

oscareriksson
Автор

Just wondering how the benchmark measures runtime: Does it scale with the number of CPU cores?
After all, a single clock cycle of a 5 Ghz CPU takes 0.2 ns. So how can any operation take 0.03 ns?

Staarfury
Автор

UTF-8 should have won some price when it came. You can save so much performance in memory transfer, cache utilization, disk-reads, network etc by using UTF-8 since common data formats like json with english terms are translated to one byte only for most characters. I think this feature can help alot to use UTF-8 encoding effectively without loads of custom-code.

gilroitto
Автор

It will be cool if they add a utf8 StringBuilder

davidwilliss
Автор

I don't like it wothout the suffix. Code should be readable without consultating the docs and just by looking you can't see how the conversion from string to byte[] is done. Could be utf16, ascii whatever. Just because most often it's utf8 should not mean that it's a language level default.

EikeSchwass
Автор

I have seen many videos in this channel and usually when talking about performance the topic of allocation comes out. My undestanding is because the allocation is a slow operation, whoever I have a questing when it comes to the GC in C#. It it better to create short leave objects (reasonable size) and then let the GC do its job, or can it be better to reuse this objects by having strong references?. The Android GC is a generational GC and the advice for mobile is to use short leaved object (contraint memory environment), the C# is also a generational GC. Its not reallt clear to me if I should use the same approach with short lived objects or just holding references in readonly fields. I guess it comes down to use cases and in API it might be bad but what about in WPF/Winforms Apps

simplegameplay