What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 2982 |  Welcome, Guest!   Register  Login
 Home > Forums > Ask Interview Questions > what is diff b/w null string and empty string ...
Yugandhar

what is diff b/w null string and empty string

Replies: 5 | Posted by: Yugandhar on 9/1/2012 | Category: Ask Interview Questions Forums | Views: 529 | Status: [Member] | Points: 10  


what is diff b/w null string and empty string
char str1[]=NULL and char str2[]="";
what is diff b/w str1 and str2 ??


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Gopesh9
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
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
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 

San.Pblr.Gct
San.Pblr.Gct  
Posted on: 9/3/2012 6:31:37 AM
Level: Starter | Status: [Member] | Points: 25

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
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 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 10:25:40 PM