-
November 15th, 2011, 05:17 AM
#1
'=' operator can not be overloaded
Hello,
I have a string x which is either null or has some value. I have to assign this value to another string y. With normal '=' (y = x) operation, I get an error if string x has null value.
I have to check first with the help of "if" statement
Code:
if(x != "") //or catch exception here
y = x;
I have to apply above code in my program everywhere I try to assign one string value to another string (and have to be careful). I would have preferably overloaded '=' operator, but have just leant that it is not possible to overlaod '='.
Can someone please suggest me another way of doing it?
Regards
Ricky
-
November 15th, 2011, 06:49 AM
#2
Re: '=' operator can not be overloaded
There shouldn't be any problem with assigning 'null' to a string variable. The below code is, if I'm not mistaken, perfectly valid:
Code:
string y = "something";
string x = null;
y = x;
What is the error / exception you are experiencing?
It's not a bug, it's a feature!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|