Constant Headache
-
Found this little nugget just now (only the name of the stored procedure was changed):
Dim strSelect As String = "exec SomeStoredProcedure " & 1
:doh:
-
I suspect the original was, and the constant was put in there when a variable was no longer required, but they didn't want to put in the extra effort of placing the constant inside the string. :doh:
-
Found this little nugget just now (only the name of the stored procedure was changed):
Dim strSelect As String = "exec SomeStoredProcedure " & 1
:doh:
Could have been worse. It could have been C# and then you would have to do
String strSelect = "exec SomeStoredProcedure " + "1";
At least VB allows the 1 to be concatenated into the string.
There are only 10 types of people in the world, those who understand binary and those who don't.
-
Could have been worse. It could have been C# and then you would have to do
String strSelect = "exec SomeStoredProcedure " + "1";
At least VB allows the 1 to be concatenated into the string.
There are only 10 types of people in the world, those who understand binary and those who don't.
ryanb31 wrote:
At least VB allows the 1 to be concatenated into the string.
Which is completely terrible that it allows you to do that. I also came across some code the other day that said something like this:
Dim str As String = "blah" & i + 1
In C#, you'd do this:
string str = "blah" + (i + 1).ToString();
Which I think is much more understandable.
-
Could have been worse. It could have been C# and then you would have to do
String strSelect = "exec SomeStoredProcedure " + "1";
At least VB allows the 1 to be concatenated into the string.
There are only 10 types of people in the world, those who understand binary and those who don't.
-
ryanb31 wrote:
At least VB allows the 1 to be concatenated into the string.
Which is completely terrible that it allows you to do that. I also came across some code the other day that said something like this:
Dim str As String = "blah" & i + 1
In C#, you'd do this:
string str = "blah" + (i + 1).ToString();
Which I think is much more understandable.
Implicit conversions works equally well in VB and C#, AFAIK. I would obviously use paratheses and
ToString
in VB as well, for clarity purposes. It's basically as easy to code badly in C# as it is in VB. In the end it's up to you.Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions
-
Implicit conversions works equally well in VB and C#, AFAIK. I would obviously use paratheses and
ToString
in VB as well, for clarity purposes. It's basically as easy to code badly in C# as it is in VB. In the end it's up to you.Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions
C# does not implicitly convert integers to strings.
-
ryanb31 wrote:
At least VB allows the 1 to be concatenated into the string.
Which is completely terrible that it allows you to do that. I also came across some code the other day that said something like this:
Dim str As String = "blah" & i + 1
In C#, you'd do this:
string str = "blah" + (i + 1).ToString();
Which I think is much more understandable.
"In C#, you'd do this:" Well i guess this is much better you know :laugh: string s = "blah" + ((i<<1)- --i);
-
Implicit conversions works equally well in VB and C#, AFAIK. I would obviously use paratheses and
ToString
in VB as well, for clarity purposes. It's basically as easy to code badly in C# as it is in VB. In the end it's up to you.Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions
Well I'll be a monkey's uncle. I just tried it and C# does allow integers to be implicitly converted to strings. Oh well, at least it does not allow the reverse.
-
Well I'll be a monkey's uncle. I just tried it and C# does allow integers to be implicitly converted to strings. Oh well, at least it does not allow the reverse.
That's a relief, I'm not senile just yet. On the other hand, I just had to check MSDN, where the C# reference claims that there is a predefined implicit conversion from int to long, float, double, or decimal[^], no mention of strings. Don't you just love their documentation.
Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions
-
That's a relief, I'm not senile just yet. On the other hand, I just had to check MSDN, where the C# reference claims that there is a predefined implicit conversion from int to long, float, double, or decimal[^], no mention of strings. Don't you just love their documentation.
Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions
Yeah, I can't find a reference to this anywhere aside from online forums. It would be neat if there's a way to disable it (like VB's option strict).