u/FireBlizzard69

▲ 39 r/dotnet

Hi, so I'm following a C# course online on my spare time. I'm still a total beginner in programming except being able to read and write on C++ with some understanding, so I've never came across more advanced techniques nor am I an expert in memory optimization. Which is why I'm curious about this: To check for input strings this guy used both the .Equals function comparing the string to string.Empty, and the .IsNullOrEmpty function. To my understanding, comparing something with string.Empty is included when you use .IsNullOrEmpty, so one might think to always just use the latter, but it could also do a potentially useless check every time you use it. My question is in which occasion do you use either, is there any way a string can be null without you manually initializing it, and why use null strings rather than empty ones in the first place, since I presume the difference in memory occupation is trivial, is the latter just more convenient if you're working with code that other people wrote? Thanks

reddit.com
u/FireBlizzard69 — 18 days ago