c# - Is there a case for a String.IsNullOrEmpty operator? -
String.IsNullOrEmpty ()
appears to be a very well-used method and I think I would like to wish there were some short stories for something like this. As it will be used for zero faculty operator in a similar context, but will be extended to test for empty and null string. I.e.
string text = some Some text ??? "Not given";
What will be your opinion on this? Will it bloat the language unnecessarily? Will the flood door have to provide such a deep unity with the compiler for other mid-level operations? Or it would be a useful addition to the language.
A time ago Phil Hack. Basically, he suggests an extension method on string
that you can do
var text = someString.AsNullIfEmpty () ?? "Not given.";
The extension method is very simple:
public static string AsNullIfEmpty (this string str) {return! String.IsNullOrEmpty (str)? Str: faucet; }
They have also suggested that instead of checking the whotspace, only with the string.IsNullOhWhitespace ()
method with .NET 4 empty space Similar Extensions IEnumerable & lt; T & gt;
interface.
for that ??? Talks about starting new operators such as
, but concluded that it would be more confusing than assistant - finally, you can do the same thing to present these extension methods, but It's more readable, and it's using the shorthand syntax which "everyone knows already".
Comments
Post a Comment