Replies |
Gopesh9
Posted on: 9/3/2012 12:49:55 AM
|
Level: Starter | Status: [Member] | Points: 25
|
See, Null means string doesn't have any value. An empty string is a value, but is just empty. Null has no bounds that means it can be used for string, integer, date.. Empty string is just regarding a string with length equals to zero.
Hope this will help you...
G. S.
.Net Developer
Yugandhar, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Ranjeet_8
Posted on: 9/3/2012 12:59:00 AM
|
Level: Gold | Status: [Member] | Points: 25
|
Empty string is allocated a memory location with value "" and the NULL value is just a pointer pointing nowhere in the memory.
Empty - It has empty value.
NULL - It has no value.
For eg :
String str = "";
str.lentgh; // return 0
String str = null;
str.lentgh; //returns a null pointer exception
Yugandhar, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Shanky11
Posted on: 9/3/2012 5:11:01 AM
|
Level: Starter | Status: [Member] | Points: 25
|
char str1[]=NULL
String str = null;
str.lentgh;
null means it will raise null pointer exception means we cant leave a field empty after defing it as not null
char str2[]=""; String str="";
str.length; output.........0
Yugandhar, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
string str=null //this will not create an object. In stack memory will be allocated for str but since its null object, no memory allocation in heap.
string str=""; //this will create an object and allocate it in heap with value "";
moreover null is NOT a value. It is a state indicating that the object value is unknown or nonexistent. It is not zero or blank or an "empty string" and it does not behave like any of these values.
Yugandhar, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Muhsinathk
Posted on: 9/3/2012 7:57:02 AM
|
Level: Bronze | Status: [Member] | Points: 25
|
In .Net pre 2.0, "" creates an object while String.Empty creates no object. So it is more efficient to use String.Empty.
.Length == 0 is the fastest option, but .Empty makes for slightly cleaner code.
So "" is pretty equivalent to .Empty, but still not as fast as .Length == 0.
Yugandhar, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|