473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

In C#, what is the difference between "\0", '\0' and null?

Consider,
Expand|Select|Wrap|Line Numbers
  1. using System;
  2.  
  3. class MainClass
  4. {
  5.     static void Main()
  6.     {
  7.         object[] ob = new object[12];
  8.  
  9.         for(int i=0; i<3; i++)
  10.             ob[i] = i;
  11.  
  12.         for(int i=3; i<6; i++)
  13.             ob[i] = (int)i/2;
  14.  
  15.         ob[6] = "string";
  16.  
  17.         ob[7] = 'c';
  18.  
  19.         ob[8] = true;
  20.  
  21.         ob[9] = DateTime.Now.ToLongDateString() + "\0" + DateTime.Now.ToLongTimeString();
  22.  
  23.         ob[10] = DateTime.Now.ToLongDateString() + '\0' + DateTime.Now.ToLongTimeString();
  24.  
  25.         ob[11] = DateTime.Now.ToLongDateString() + null + DateTime.Now.ToLongTimeString();
  26.  
  27.  
  28.  
  29.         for(int i=0; i<ob.Length; i++)
  30.             Console.WriteLine("ob[{0}] = {1}", i, ob[i]);
  31.     }
  32. }
  33.  
\0 is an escape sequence described as null.

But why is the difference between "\0", '\0' and null as in the program where ob[11] has no space between DateTime.Now.ToLongDateString() and DateTime.Now.ToLongTimeString(), but ob[9] and ob[10] have?
Jul 27 '07 #1
3 7397
Frinavale
9,735 Expert Mod 8TB
Hi Rajanipro,


I have moved your question to the .NET forum. The .NET Articles section is reserved for articles that are purely informational; like "how-tos" etc. The .NET Forum is the place for your questions. In the future please post your questions here (Blue Menu Along the Top: Forums->.NET).

Cheers!
-Frinny
Jul 30 '07 #2
Plater
7,872 Expert 4TB
'\0' is character data with character code 0 (0x00 if you prefer)
"\0" is string data, containing one character, the 0x00 character, which, since it's used as a string delimeter and other special cases, will not be displayed and is considered null.
NULL is null, sometimes defined as a pointer to a memory location 0x0000 (or any other versions of zero) which is a special pointer that means "does not exist"
They are all used for different things.
For example, setting a variable to NULL effectively "un-defines" it in the sense that it's memory is now floating, and managed code (.NET) will not allow you to access it and throws a NULL reference exception.
Jul 30 '07 #3
Thank you very much indeed!
Jul 30 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Steven Scaife | last post by:
I have a quick question i tried searching google but couldn't find anything What is the difference between not isnull(val) and <> "" can this statement be reduced from If NumberDep <> "" or...
3
by: Paul T. Rong | last post by:
Do "" and Null both mean nothing?¡¡ If I don't type anything in text box, the its value is Null£¿¡¡Or it is ¡°¡±£¿ I don¡¯ think they are the same, but I don¡¯t know their difference. Thanks.
3
by: Fei Li | last post by:
Hi, take string class as an example, who can explain the difference? Thanks
14
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects...
10
by: Flip | last post by:
I know the int.Parse("123") will result in an int of 123, but what happens with a null? I believe it give a null exception (seems like I get either NullArgumentException or ArgumentNullException...
8
by: David Cameron | last post by:
I noticed that using an HTMLInputRadioButton and specifying a value to be an empty string (""), this is overridden by ASP.Net which set the value of the control to be the same as the ID of the...
6
by: John Pass | last post by:
What is the difference between a While and Do While/Loop repetition structure. If they is no difference (as it seems) why do both exist?
26
by: anonieko | last post by:
In the past I always used "" everywhere for empty string in my code without a problem. Now, do you think I should use String.Empty instead of "" (at all times) ? Let me know your thoughts.
0
NeoPa
by: NeoPa | last post by:
Intention : To prepare a WHERE clause for multiple field selection, but to ignore any fields where the selection criteria are not set. ONLY WORKS WITH TEXT FIELD SELECTIONS. Scenario : You have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.