473,320 Members | 1,857 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,320 software developers and data experts.

Null question

Are these two statements identical?

public static string Var1 = "";
public static string Var1 = null;

I read somewhere that there was a difference, but I haven't found it. Any
ideas?
Nov 16 '05 #1
4 1002
In the first version, Var1 references a string with the value "".
In the second version, Var1 does not reference a string at all.

Regards,
Joakim

Keith Smith wrote:
Are these two statements identical?

public static string Var1 = "";
public static string Var1 = null;

I read somewhere that there was a difference, but I haven't found it. Any
ideas?

Nov 16 '05 #2
Keith Smith wrote:
Are these two statements identical?

public static string Var1 = "";
public static string Var1 = null;

I read somewhere that there was a difference, but I haven't found it.
Any ideas?


Why on earth should these be identical?

The first line assigns the empty string (a live object) to Var1. The
second line assigns, um, nothing (i.e. no live object) to Var1.

So

Console.WriteLine(Var1);
Console.WriteLine(Var1.Length);
Console.WriteLine(Var1.GetHashCode());

will work fine for "", but will crash on the second line for null.
Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 16 '05 #3
"Keith Smith" <ke*********@verizon.net> wrote in message
news:FDlPd.25632$Dc.815@trnddc06...
Are these two statements identical?

public static string Var1 = "";
public static string Var1 = null;

I read somewhere that there was a difference, but I haven't found it. Any
ideas?


How about string var1 = string.Empty;


Nov 16 '05 #4
That is basically the same thing as string var1 = "".

Regards,
Joakim

Zach wrote:

How about string var1 = string.Empty;

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Dmitry D | last post by:
Hi, I'm new to C++ (started learning in the beginning of this summer), and I have the following question (sorry if it sounds stupid): In many code samples and source files, I see NULL expression...
26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
8
by: sugaray | last post by:
Hi, I just came upon this code snippet which parses a string stored in buf with comma(,) as delimiter and store each substring into args, the question I'm having here is that I don't get why in the...
41
by: Alexei A. Frounze | last post by:
Seems like, to make sure that a pointer doesn't point to an object/function, NULL (or simply 0) is good enough for both kind of pointers, data pointers and function pointers as per 6.3.2.3: 3 An...
13
by: Federico Balbi | last post by:
Hi, I was wondering if PGSQL has a function similar to binary_checksum() of MS SQL Server 2000. It is pretty handy when it comes to compare rows of data instead of having to write long boolean...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
13
by: Jiho Han | last post by:
Here's the issue. You have a class, Class Person { public int id; public string firstname; public string lastname; }
51
by: muktipada | last post by:
Hello, As a C++ developer which one we should use for pointer assignment, NULL or 0. typedef DummyC DummyClass*; // in some header file. DummyC obj = NULL; if (obj == NULL) {
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.