Is string.Empty actually better than '' in C#?

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

Hello everybody I'm Nick and in this video I am going to answer one of the questions I see floating around time and time again and that is, is string.Empty the same as empty string in C#. There are multiple assumptions about this and even stackoverflow answers that state completely wrong stuff so hopefully in this video I will teach you how you can answer those questions on your own.

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

Social Media:

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

That intro is quite cool. Usually youtubes get out of their way to keep you watching for as long as possible. Breath of fresh air.

macx
Автор

I've seen quite a lot of your videos, and every one does a stupendous job at explaining things that I didn't know about C#. I've always enjoyed each video, but this video is the one that made me decide to subscribe. Thanks for not wasting the average viewer's time by giving us the answer right away, but also thanks for teaching the people who do want to stick around about all the nuances and reasons for why that answer is the answer.

not__nugget
Автор

When he gave the answer in the intro I straight up subscribed and stayed for more information.

SenzoDlomo
Автор

It's brilliant to show how you investigate this. it's "learn a man to fish..." I prefer "string. Empty" as it tells the intent clearly, but that's a different story. Thanx Nick

noblenetdk
Автор

Upvoted and subscribed for giving the answer straight off and not making us wait to the end.

scottburfield-mills
Автор

Thanks for the video.
Code wise, In my opinion string.Empty is safer, I experienced that I or someone else by mistake put white space between "", So it took us long time to figure out what went wrong.

peymannaji
Автор

I subbed because you told me the answer in the first 1 minute - I watched the rest, I wanted to know why - but thanks for not wasting our time.

TheDuerden
Автор

It was a VERY diplomatic way of saying that you think "" is the cleanest. .. in which I totally agree.

realsk
Автор

I admire straightforward conclusion at the beginning on the video. Like & subscription for you mate!

TheSkowoo
Автор

This is very nice and interesting learning how to utilise the IL to inspect and dig into what's actually happening. Nice!

Radictor
Автор

You spit the answer right in the beginning of the video, thats pretty cool.
Left the video playing until the end instead of leaving 👍

Ferdam
Автор

I appreciate that you answered the question immediately. Nick for president!

Maritims
Автор

Just watched a video with a _very_ similar premise for C++, and the answer was wildly different. string::clear() is a method, so it can dodge deallocation/length checks/etc; assigning an empty string is slower. Interesting how different languages have different approaches like that

berylliosis
Автор

Great work explaining it deeply.
We rather use String.Empty, just because it looks cleaner.

PticostaricaGS
Автор

Great content,
I would like to see more videos like this exploring the IL, Jit and what is happing at behind

reza.kargar
Автор

I love your channel! Thanks for answering the question in the first few seconds and not force me to watch the whole. Btw i did watch it through even tho i was only interested in the result

ib
Автор

If for some reason there were to be an environment where empty string was not "", not sure how that could ever be but seemed like using string.Empty would be similar to using Environment.NewLine versus a literal "\n\r".

digitalman
Автор

Excellent video Nick, short and to the point.

markharby
Автор

The main reason to prefer string.Empty where possible over "", is that the first shows intend. "" could be an empty string, or it could be a string you forgot to fill in.

MulleDK
Автор

I came in expecting to be indoctrinated into one or the other, instead learned about interning and no longer care, and my opinion says the same as your turned out to be. Thank you!

DoorThief