Why doesn't a String of Nothing cause cause an exception? (BC42104) [duplicate]Difference between Equals/equals and == operator?Nothing = String.Empty (Why are these equal?)Why is Dictionary preferred over Hashtable in C#?Compiler warning: null reference exceptionVariable 'cl' is passed by reference before it has been assigned a value for DataView Variablewarning BC42104 - Variable used before assigned a valueNull Reference List(of String)Why does checking if an object is null cause a warning at compile time?Visual Basic warningvariable “stat_in” is used before it has been assigned a value. a null exception could result at runtimeVariable 'reader' is used before it has been assigned a value. A null reference exception could result at run timeVB.Net no idea how to get this to compile also Retro BASIC

How can I reorder triggered abilities in Arena?

“T” in subscript in formulas

What does "rel" in `mathrel` and `stackrel` stands for?

How to respectfully refuse to assist co-workers with IT issues?

Does this VCO produce a sine wave or square wave

Can a giant mushroom be used as a material to build watercraft or sailing ships?

Removal of て in Japanese novels

"Opusculum hoc, quamdiu vixero, doctioribus emendandum offero."?

Command "root" and "subcommands"

Why do banks “park” their money at the European Central Bank?

Rent contract say that pets are not allowed. Possible repercussions if bringing the pet anyway?

I don't have the theoretical background in my PhD topic. I can't justify getting the degree

Add 2 new columns to existing dataframe using apply

How long do you think advanced cybernetic implants would plausibly last?

How do I make my image comply with the requirements of this photography competition?

How do I prevent other wifi networks from showing up on my computer?

Why does Windows store Wi-Fi passwords in a reversible format?

Another solution to create a set with two conditions

To get so rich that you are not in need of anymore money

Boot Windows from SAN

"fF" letter combination seems to be typeset strangely or incorrectly

Ordering a list of integers

Server Integrity Check CheckCommands question

"There were either twelve sexes or none."



Why doesn't a String of Nothing cause cause an exception? (BC42104) [duplicate]


Difference between Equals/equals and == operator?Nothing = String.Empty (Why are these equal?)Why is Dictionary preferred over Hashtable in C#?Compiler warning: null reference exceptionVariable 'cl' is passed by reference before it has been assigned a value for DataView Variablewarning BC42104 - Variable used before assigned a valueNull Reference List(of String)Why does checking if an object is null cause a warning at compile time?Visual Basic warningvariable “stat_in” is used before it has been assigned a value. a null exception could result at runtimeVariable 'reader' is used before it has been assigned a value. A null reference exception could result at run timeVB.Net no idea how to get this to compile also Retro BASIC






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0
















This question already has an answer here:



  • Difference between Equals/equals and == operator?

    11 answers



If I declare a string but do not assign a value, the Equals function throws an exception but it doesn't throw an exception if it is compared to a value.



The error list warns about the problem:




Warning BC42104 Variable a is used before it has been assigned a
value. A null reference exception could result at runtime.




Dim a As String
Dim b as string = "bar"

a.Equals("foo") 'causes System.NullReferenceException

a = "foo" 'No exception although a is nothing

a = b 'No exception although a is nothing


I know the warning says it COULD cause an exception, but does anyone know why this is the happening?










share|improve this question
















marked as duplicate by Cody Gray vb.net
Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 19:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Nothing and Strings in Visual Basic

    – TnTinMn
    Mar 27 at 19:09











  • The warning is pretty much unrelated. It can always be Nothing, even if initialized; for example, the warning will go away if you write Dim a As String = Nothing. Is your real question about the difference between the = operator and the .Equals method?

    – Ry-
    Mar 27 at 19:15






  • 1





    a.Equals is calling a member function on a. Obviously you cannot call a member function on an object that is "null"/Nothing. However, the equality operator is special-cased to handle null objects.

    – Cody Gray
    Mar 27 at 19:16






  • 1





    (Also, please confirm that you’re using a = "foo" and a = b in an expression and not as a statement – preferably with real code – because it’s also a valid assignment statement. Since you already got an answer that was confused about that.)

    – Ry-
    Mar 27 at 19:16






  • 1





    To elaborate on what @CodyGray is saying, also note that string.operator==(string, string), like all overloaded operators, is static (Shared), at no point does the .NET framework try to do a.Equals when it handles the = operator; string.Equals(string), on the other hand is an instance method of String and will cause a NullReferenceException.

    – jrh
    Mar 27 at 19:20


















0
















This question already has an answer here:



  • Difference between Equals/equals and == operator?

    11 answers



If I declare a string but do not assign a value, the Equals function throws an exception but it doesn't throw an exception if it is compared to a value.



The error list warns about the problem:




Warning BC42104 Variable a is used before it has been assigned a
value. A null reference exception could result at runtime.




Dim a As String
Dim b as string = "bar"

a.Equals("foo") 'causes System.NullReferenceException

a = "foo" 'No exception although a is nothing

a = b 'No exception although a is nothing


I know the warning says it COULD cause an exception, but does anyone know why this is the happening?










share|improve this question
















marked as duplicate by Cody Gray vb.net
Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 19:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Nothing and Strings in Visual Basic

    – TnTinMn
    Mar 27 at 19:09











  • The warning is pretty much unrelated. It can always be Nothing, even if initialized; for example, the warning will go away if you write Dim a As String = Nothing. Is your real question about the difference between the = operator and the .Equals method?

    – Ry-
    Mar 27 at 19:15






  • 1





    a.Equals is calling a member function on a. Obviously you cannot call a member function on an object that is "null"/Nothing. However, the equality operator is special-cased to handle null objects.

    – Cody Gray
    Mar 27 at 19:16






  • 1





    (Also, please confirm that you’re using a = "foo" and a = b in an expression and not as a statement – preferably with real code – because it’s also a valid assignment statement. Since you already got an answer that was confused about that.)

    – Ry-
    Mar 27 at 19:16






  • 1





    To elaborate on what @CodyGray is saying, also note that string.operator==(string, string), like all overloaded operators, is static (Shared), at no point does the .NET framework try to do a.Equals when it handles the = operator; string.Equals(string), on the other hand is an instance method of String and will cause a NullReferenceException.

    – jrh
    Mar 27 at 19:20














0












0








0









This question already has an answer here:



  • Difference between Equals/equals and == operator?

    11 answers



If I declare a string but do not assign a value, the Equals function throws an exception but it doesn't throw an exception if it is compared to a value.



The error list warns about the problem:




Warning BC42104 Variable a is used before it has been assigned a
value. A null reference exception could result at runtime.




Dim a As String
Dim b as string = "bar"

a.Equals("foo") 'causes System.NullReferenceException

a = "foo" 'No exception although a is nothing

a = b 'No exception although a is nothing


I know the warning says it COULD cause an exception, but does anyone know why this is the happening?










share|improve this question

















This question already has an answer here:



  • Difference between Equals/equals and == operator?

    11 answers



If I declare a string but do not assign a value, the Equals function throws an exception but it doesn't throw an exception if it is compared to a value.



The error list warns about the problem:




Warning BC42104 Variable a is used before it has been assigned a
value. A null reference exception could result at runtime.




Dim a As String
Dim b as string = "bar"

a.Equals("foo") 'causes System.NullReferenceException

a = "foo" 'No exception although a is nothing

a = b 'No exception although a is nothing


I know the warning says it COULD cause an exception, but does anyone know why this is the happening?





This question already has an answer here:



  • Difference between Equals/equals and == operator?

    11 answers







vb.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 19:13









Milo

2,1116 gold badges19 silver badges33 bronze badges




2,1116 gold badges19 silver badges33 bronze badges










asked Mar 27 at 18:51









UggyUggy

32 bronze badges




32 bronze badges





marked as duplicate by Cody Gray vb.net
Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 19:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











marked as duplicate by Cody Gray vb.net
Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 19:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Cody Gray vb.net
Users with the  vb.net badge can single-handedly close vb.net questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 27 at 19:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 1





    Nothing and Strings in Visual Basic

    – TnTinMn
    Mar 27 at 19:09











  • The warning is pretty much unrelated. It can always be Nothing, even if initialized; for example, the warning will go away if you write Dim a As String = Nothing. Is your real question about the difference between the = operator and the .Equals method?

    – Ry-
    Mar 27 at 19:15






  • 1





    a.Equals is calling a member function on a. Obviously you cannot call a member function on an object that is "null"/Nothing. However, the equality operator is special-cased to handle null objects.

    – Cody Gray
    Mar 27 at 19:16






  • 1





    (Also, please confirm that you’re using a = "foo" and a = b in an expression and not as a statement – preferably with real code – because it’s also a valid assignment statement. Since you already got an answer that was confused about that.)

    – Ry-
    Mar 27 at 19:16






  • 1





    To elaborate on what @CodyGray is saying, also note that string.operator==(string, string), like all overloaded operators, is static (Shared), at no point does the .NET framework try to do a.Equals when it handles the = operator; string.Equals(string), on the other hand is an instance method of String and will cause a NullReferenceException.

    – jrh
    Mar 27 at 19:20













  • 1





    Nothing and Strings in Visual Basic

    – TnTinMn
    Mar 27 at 19:09











  • The warning is pretty much unrelated. It can always be Nothing, even if initialized; for example, the warning will go away if you write Dim a As String = Nothing. Is your real question about the difference between the = operator and the .Equals method?

    – Ry-
    Mar 27 at 19:15






  • 1





    a.Equals is calling a member function on a. Obviously you cannot call a member function on an object that is "null"/Nothing. However, the equality operator is special-cased to handle null objects.

    – Cody Gray
    Mar 27 at 19:16






  • 1





    (Also, please confirm that you’re using a = "foo" and a = b in an expression and not as a statement – preferably with real code – because it’s also a valid assignment statement. Since you already got an answer that was confused about that.)

    – Ry-
    Mar 27 at 19:16






  • 1





    To elaborate on what @CodyGray is saying, also note that string.operator==(string, string), like all overloaded operators, is static (Shared), at no point does the .NET framework try to do a.Equals when it handles the = operator; string.Equals(string), on the other hand is an instance method of String and will cause a NullReferenceException.

    – jrh
    Mar 27 at 19:20








1




1





Nothing and Strings in Visual Basic

– TnTinMn
Mar 27 at 19:09





Nothing and Strings in Visual Basic

– TnTinMn
Mar 27 at 19:09













The warning is pretty much unrelated. It can always be Nothing, even if initialized; for example, the warning will go away if you write Dim a As String = Nothing. Is your real question about the difference between the = operator and the .Equals method?

– Ry-
Mar 27 at 19:15





The warning is pretty much unrelated. It can always be Nothing, even if initialized; for example, the warning will go away if you write Dim a As String = Nothing. Is your real question about the difference between the = operator and the .Equals method?

– Ry-
Mar 27 at 19:15




1




1





a.Equals is calling a member function on a. Obviously you cannot call a member function on an object that is "null"/Nothing. However, the equality operator is special-cased to handle null objects.

– Cody Gray
Mar 27 at 19:16





a.Equals is calling a member function on a. Obviously you cannot call a member function on an object that is "null"/Nothing. However, the equality operator is special-cased to handle null objects.

– Cody Gray
Mar 27 at 19:16




1




1





(Also, please confirm that you’re using a = "foo" and a = b in an expression and not as a statement – preferably with real code – because it’s also a valid assignment statement. Since you already got an answer that was confused about that.)

– Ry-
Mar 27 at 19:16





(Also, please confirm that you’re using a = "foo" and a = b in an expression and not as a statement – preferably with real code – because it’s also a valid assignment statement. Since you already got an answer that was confused about that.)

– Ry-
Mar 27 at 19:16




1




1





To elaborate on what @CodyGray is saying, also note that string.operator==(string, string), like all overloaded operators, is static (Shared), at no point does the .NET framework try to do a.Equals when it handles the = operator; string.Equals(string), on the other hand is an instance method of String and will cause a NullReferenceException.

– jrh
Mar 27 at 19:20






To elaborate on what @CodyGray is saying, also note that string.operator==(string, string), like all overloaded operators, is static (Shared), at no point does the .NET framework try to do a.Equals when it handles the = operator; string.Equals(string), on the other hand is an instance method of String and will cause a NullReferenceException.

– jrh
Mar 27 at 19:20













1 Answer
1






active

oldest

votes


















1















This is because Dim a As String declares the type of variable a but doesn't assign anything to it. This is basically saying : "This variable was made to hold a String object, but it doesn't hold any right now". On the other hand, Dim b As String = "bar" declares the variable and its type, but also assigns a String object to it ("bar"). The reason a.Equals("foo") returns an exception is because you only declared it without assigning anything to it (so you are trying to access an object that isn't there). a = "foo" works because you are assigning a String object of value "foo" to the variable a. It's like saying : "This variable now holds a String object with value 'foo'".



Edit :



While your code points to the assignment of the variable a, I was made aware that you wanted to know why the = operator, as a comparison operator, works. This is because what I said earlier isn't entirely true when I said it didn't hold an object. It actually is of Nothing value (which sets it as a null reference) if no String object was assigned to it (String is a nullable object).



See : https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/nothing



Hope this helps.






share|improve this answer



























  • The question is about string comparison -- "it doesn't throw an exception if it is compared to a value". The code presented leads one to assume it is about assignment.

    – TnTinMn
    Mar 27 at 19:13











  • @TnTinMn this is true. I was looking at the code given. If the a = "foo" expression is used in an If statement, I assume it works because a is treated as a Nothing object, which works with the = operator.

    – Olivier Samson
    Mar 27 at 19:25











  • You might as well cover both contingencies in your answer before someone else does. Also look at the link I posted as comment.

    – TnTinMn
    Mar 27 at 19:30











  • Yes this was in an If statement. Hence I was expecting an exception (like in C#) but reading TnTinMn link I see now that the VB runtime treats a string of nothing as an empty string, which now makes sense of this.

    – Uggy
    Mar 28 at 8:42











  • @Uggy: ”Like in C#” – ? null == "foo" works fine in C# too with no exception.

    – Ry-
    Mar 28 at 20:35















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1















This is because Dim a As String declares the type of variable a but doesn't assign anything to it. This is basically saying : "This variable was made to hold a String object, but it doesn't hold any right now". On the other hand, Dim b As String = "bar" declares the variable and its type, but also assigns a String object to it ("bar"). The reason a.Equals("foo") returns an exception is because you only declared it without assigning anything to it (so you are trying to access an object that isn't there). a = "foo" works because you are assigning a String object of value "foo" to the variable a. It's like saying : "This variable now holds a String object with value 'foo'".



Edit :



While your code points to the assignment of the variable a, I was made aware that you wanted to know why the = operator, as a comparison operator, works. This is because what I said earlier isn't entirely true when I said it didn't hold an object. It actually is of Nothing value (which sets it as a null reference) if no String object was assigned to it (String is a nullable object).



See : https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/nothing



Hope this helps.






share|improve this answer



























  • The question is about string comparison -- "it doesn't throw an exception if it is compared to a value". The code presented leads one to assume it is about assignment.

    – TnTinMn
    Mar 27 at 19:13











  • @TnTinMn this is true. I was looking at the code given. If the a = "foo" expression is used in an If statement, I assume it works because a is treated as a Nothing object, which works with the = operator.

    – Olivier Samson
    Mar 27 at 19:25











  • You might as well cover both contingencies in your answer before someone else does. Also look at the link I posted as comment.

    – TnTinMn
    Mar 27 at 19:30











  • Yes this was in an If statement. Hence I was expecting an exception (like in C#) but reading TnTinMn link I see now that the VB runtime treats a string of nothing as an empty string, which now makes sense of this.

    – Uggy
    Mar 28 at 8:42











  • @Uggy: ”Like in C#” – ? null == "foo" works fine in C# too with no exception.

    – Ry-
    Mar 28 at 20:35
















1















This is because Dim a As String declares the type of variable a but doesn't assign anything to it. This is basically saying : "This variable was made to hold a String object, but it doesn't hold any right now". On the other hand, Dim b As String = "bar" declares the variable and its type, but also assigns a String object to it ("bar"). The reason a.Equals("foo") returns an exception is because you only declared it without assigning anything to it (so you are trying to access an object that isn't there). a = "foo" works because you are assigning a String object of value "foo" to the variable a. It's like saying : "This variable now holds a String object with value 'foo'".



Edit :



While your code points to the assignment of the variable a, I was made aware that you wanted to know why the = operator, as a comparison operator, works. This is because what I said earlier isn't entirely true when I said it didn't hold an object. It actually is of Nothing value (which sets it as a null reference) if no String object was assigned to it (String is a nullable object).



See : https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/nothing



Hope this helps.






share|improve this answer



























  • The question is about string comparison -- "it doesn't throw an exception if it is compared to a value". The code presented leads one to assume it is about assignment.

    – TnTinMn
    Mar 27 at 19:13











  • @TnTinMn this is true. I was looking at the code given. If the a = "foo" expression is used in an If statement, I assume it works because a is treated as a Nothing object, which works with the = operator.

    – Olivier Samson
    Mar 27 at 19:25











  • You might as well cover both contingencies in your answer before someone else does. Also look at the link I posted as comment.

    – TnTinMn
    Mar 27 at 19:30











  • Yes this was in an If statement. Hence I was expecting an exception (like in C#) but reading TnTinMn link I see now that the VB runtime treats a string of nothing as an empty string, which now makes sense of this.

    – Uggy
    Mar 28 at 8:42











  • @Uggy: ”Like in C#” – ? null == "foo" works fine in C# too with no exception.

    – Ry-
    Mar 28 at 20:35














1














1










1









This is because Dim a As String declares the type of variable a but doesn't assign anything to it. This is basically saying : "This variable was made to hold a String object, but it doesn't hold any right now". On the other hand, Dim b As String = "bar" declares the variable and its type, but also assigns a String object to it ("bar"). The reason a.Equals("foo") returns an exception is because you only declared it without assigning anything to it (so you are trying to access an object that isn't there). a = "foo" works because you are assigning a String object of value "foo" to the variable a. It's like saying : "This variable now holds a String object with value 'foo'".



Edit :



While your code points to the assignment of the variable a, I was made aware that you wanted to know why the = operator, as a comparison operator, works. This is because what I said earlier isn't entirely true when I said it didn't hold an object. It actually is of Nothing value (which sets it as a null reference) if no String object was assigned to it (String is a nullable object).



See : https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/nothing



Hope this helps.






share|improve this answer















This is because Dim a As String declares the type of variable a but doesn't assign anything to it. This is basically saying : "This variable was made to hold a String object, but it doesn't hold any right now". On the other hand, Dim b As String = "bar" declares the variable and its type, but also assigns a String object to it ("bar"). The reason a.Equals("foo") returns an exception is because you only declared it without assigning anything to it (so you are trying to access an object that isn't there). a = "foo" works because you are assigning a String object of value "foo" to the variable a. It's like saying : "This variable now holds a String object with value 'foo'".



Edit :



While your code points to the assignment of the variable a, I was made aware that you wanted to know why the = operator, as a comparison operator, works. This is because what I said earlier isn't entirely true when I said it didn't hold an object. It actually is of Nothing value (which sets it as a null reference) if no String object was assigned to it (String is a nullable object).



See : https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/nothing



Hope this helps.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 27 at 19:32

























answered Mar 27 at 19:09









Olivier SamsonOlivier Samson

5112 silver badges11 bronze badges




5112 silver badges11 bronze badges















  • The question is about string comparison -- "it doesn't throw an exception if it is compared to a value". The code presented leads one to assume it is about assignment.

    – TnTinMn
    Mar 27 at 19:13











  • @TnTinMn this is true. I was looking at the code given. If the a = "foo" expression is used in an If statement, I assume it works because a is treated as a Nothing object, which works with the = operator.

    – Olivier Samson
    Mar 27 at 19:25











  • You might as well cover both contingencies in your answer before someone else does. Also look at the link I posted as comment.

    – TnTinMn
    Mar 27 at 19:30











  • Yes this was in an If statement. Hence I was expecting an exception (like in C#) but reading TnTinMn link I see now that the VB runtime treats a string of nothing as an empty string, which now makes sense of this.

    – Uggy
    Mar 28 at 8:42











  • @Uggy: ”Like in C#” – ? null == "foo" works fine in C# too with no exception.

    – Ry-
    Mar 28 at 20:35


















  • The question is about string comparison -- "it doesn't throw an exception if it is compared to a value". The code presented leads one to assume it is about assignment.

    – TnTinMn
    Mar 27 at 19:13











  • @TnTinMn this is true. I was looking at the code given. If the a = "foo" expression is used in an If statement, I assume it works because a is treated as a Nothing object, which works with the = operator.

    – Olivier Samson
    Mar 27 at 19:25











  • You might as well cover both contingencies in your answer before someone else does. Also look at the link I posted as comment.

    – TnTinMn
    Mar 27 at 19:30











  • Yes this was in an If statement. Hence I was expecting an exception (like in C#) but reading TnTinMn link I see now that the VB runtime treats a string of nothing as an empty string, which now makes sense of this.

    – Uggy
    Mar 28 at 8:42











  • @Uggy: ”Like in C#” – ? null == "foo" works fine in C# too with no exception.

    – Ry-
    Mar 28 at 20:35

















The question is about string comparison -- "it doesn't throw an exception if it is compared to a value". The code presented leads one to assume it is about assignment.

– TnTinMn
Mar 27 at 19:13





The question is about string comparison -- "it doesn't throw an exception if it is compared to a value". The code presented leads one to assume it is about assignment.

– TnTinMn
Mar 27 at 19:13













@TnTinMn this is true. I was looking at the code given. If the a = "foo" expression is used in an If statement, I assume it works because a is treated as a Nothing object, which works with the = operator.

– Olivier Samson
Mar 27 at 19:25





@TnTinMn this is true. I was looking at the code given. If the a = "foo" expression is used in an If statement, I assume it works because a is treated as a Nothing object, which works with the = operator.

– Olivier Samson
Mar 27 at 19:25













You might as well cover both contingencies in your answer before someone else does. Also look at the link I posted as comment.

– TnTinMn
Mar 27 at 19:30





You might as well cover both contingencies in your answer before someone else does. Also look at the link I posted as comment.

– TnTinMn
Mar 27 at 19:30













Yes this was in an If statement. Hence I was expecting an exception (like in C#) but reading TnTinMn link I see now that the VB runtime treats a string of nothing as an empty string, which now makes sense of this.

– Uggy
Mar 28 at 8:42





Yes this was in an If statement. Hence I was expecting an exception (like in C#) but reading TnTinMn link I see now that the VB runtime treats a string of nothing as an empty string, which now makes sense of this.

– Uggy
Mar 28 at 8:42













@Uggy: ”Like in C#” – ? null == "foo" works fine in C# too with no exception.

– Ry-
Mar 28 at 20:35






@Uggy: ”Like in C#” – ? null == "foo" works fine in C# too with no exception.

– Ry-
Mar 28 at 20:35









Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.





Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript