How to VB.NET String Null
How to handle null String ?
A VB.NET string is an array of characters declared using the string keyword. String objects are immutable, meaning that they cannot be changed once they have been created.
What is VB.NET null ?
A null value is a value that doesnt refer to any object. Strings are reference types and can be equal to the null value like any other reference type. VB.NET uses the keyword Nothing for null values. When defining a string in a class, dont initialize it to null. Instead, initialize it to the constant String.Empty.
What is an Empty Strings ?
An empty string is an instance of a System.String object that contains zero characters. Empty strings are used quite commonly in various programming scenarios to represent a blank text field. Empty strings are initialized like this:
What is a Null Strings ?
A null string does not refer to an instance of a System.String object and any attempt to call a method on a null string results in a NullReferenceException. e.g. given below.
When run the above code it will throw NullReferenceException.
How to check null String in vb.net ?
VB.NET uses the keyword Nothing for null values.
In the above code we created a string Object and assigned Nothing and next we check the string is null or not.
IsNullOrEmpty is a convenience method that enables you to simultaneously test whether a String is Nothing or its value is Empty. It is equivalent to the following code:
result = s Is Nothing OrElse s = String.Empty
NullReferenceException indicates that you are trying to access member fields, or function types, on an object reference that points to null. That means the reference to an Object which is not initialized. More about.... NullReferenceException