One of the subtle (but cool) language features of C# is the?? 'null coalescing' operator. This provides a nice, terse way to check whether a value is.
String. IsNullOrEmpty. Maybe some of you are already using this. But for others, it could be a great utility method. We use a static method IsNullOrEmpty of string in most of our daily task/projects a lot.
It works fine in most of the cases, but it could work bizarre in some cases if not handled properly. Say, you get a entry from UI, and having a check whether user has entered something or not.
It would work fine as long as user enters the data or not. But what happen if user enters just spaces. This method would return false. ironically this method is behaving as coded. But do we need this.
I have a form and stored procedure that inserts the data from the form. It works fine except that if a field isn't filled in it doesn't insert a NULL into SQL it inserts. In several languages NULL is handled differently: Most people know about two-valued logic where true and false are the only comparable values in boolean expressions.
Obviously not, spaces could lead to wrong entry in our database even can corrupt the data and leads to uncommon results/Y SODS/malfunctioning. Although being a good developer, one always trims the input before having the check. But it also tends a lots of extra LOCs which we can save and can make our system less error prone. Most of us are aware of the beauty of the extension methods that were introduced in C# 3. So we can have an extension method over a string. which actually does both; first trimming and then checking for IsNullOrEmpty.
So we can have the extension method as:. One more smarter code would be. Let's see both the existing and our new method running. The output is:.
Handling NULL in T-SQL; Author: Bhim B Thapa; Updated:; Section: Database; Chapter: Database; Updated. Мое знакомство с ASP.NET MVC в Visual Studio 2015 на примере построения прототипа МИС из песочницы.
But if you are still using. NET 2. 0, you can have a normal static method in your utility call, which does the job for us. Note: I must say, the limitation of the existing IsNullorEmpty has been resolved in. NET 4. It means you don’t need to do all this.
There is a new method String. IsNullOrWhiteSpace will do both for you. But unlikely, most of us are still working on. NET2. 0/3.
Hope you all must have liked it.