I am primarily a C# developer, I will admit up front that I dislike VB.Net and will avoid using it when I can. I am not going to get into why here because I don’t want to spark all kind of needless arguments. Let’s just say I am heavily biased towards C# just like I am heavily biased towards using and loving Microsoft Products. I am a Microsoft whore – it keeps me employed so I feel indebted to it…and I like it…makes me feel dirty…
So I made a grimy discovery yesterday and I want to share it here because this is a big gotcha. When I use the immediate window with C# I just type in whatever it is that I want to inspect and hit return. I started using the immediate window with VB.Net recently and I kept getting this meaningless error that read:
“Property access must assign to the property or use its value”
This is a screen capture of my immediate window. The first line is the failure and the second line is the right way to do it with VB.Net.
This was very troubling to me at first because this is not the first time I have ever used the immediate window, so I then remembered that I had to do something with a question mark, but I thought that was only for the Command Window, apparently I was wrong… kind of.
I did a google search and I found this page: http://forums.asp.net/t/1091662.aspx/1
I had a head palm moment and realized that you are really supposed to use a “?” before your arguments in the immediate window. I never had to bother with this before for C#, it appears to only happen with VB.Net.
So the Gotcha of today is…
- When using an immediate window with VB.Net you are required to start your arguments with a question mark “?”.
- When using an immediate window with C# you are not required in most instances to use a question mark before your arguments. I can’t prove this, but if you look at this link http://msdn.microsoft.com/en-us/library/f177hahy(v=vs.90).aspx you will see that they show the example with VB.Net and don’t bother with C#, I think that means something.
- When you want to evaluate a statement (IE: Set a value) in the immediate window with VB.Net, do not include the question mark “?” because you will just receive an unhelpful error. This is not required in C#.