Maybe my knowlegde is not up to date. last time I saw VB it was
a hybrid language like C++, that allowed normal functions or
variables not to belong to a class.
In .NET, all classes inherit from Object, so you can do the same thing
you can in C# and assign any type to an Object variable.
But you can also leave it out or forget it and you have a problem. What if
the implementor of the library you are using leaves it out?
If the implementer of the library you're using is a bad programmer, then
he's a bad programmer. Using a library written by someone who doesn't know
what he's doing will cause just as many problems no matter what language
he's using.
VB calls its methods with late binding that means you can call
methods that are not in this type
You can do late binding if Option Strict is disabled, but only idiots do
that. And, like I said, idiots will find ways to screw up in C# just as
easily as they will in VB.
Can you explain this feature or give an example? How can I implement a
interface when I don't have a method with a suiting signature?
The method has to have a matching signature, but you can use any name or
scope you want. Here's the classic example:
Public Class TestClass
Implements IDisposable
Public Sub Close() Implements IDisposable.Dispose
...
End Sub
End Class
Dim test1 As TestClass = New TestClass
Dim test2 As TestClass = New TestClass
' These statements are equivalent
test1.Close
DirectCast(test2, IDisposable).Dispose
You could make the method which implements IDisposable.Dispose have any
scope and name you want. You could also have the same method implement more
than one interface member:
Public Class MultiClass
Implements MyInterface1, MyInterface2
Private Sub MyMethod Implements MyInterface1.Method1, MyInterface2.Method2
...
End Sub
End Class
It's a very useful mechanism, and can potentially save a lot of coding.
Being able to declare Private methods to implement the interface is useful
if you don't want to expose those methods outside the interface context; for
example, when you have an object which implements many interfaces and don't
want 100 methods cluttering things up when you'll never use them unless
you're already casting to that interface type.
with blocks are stupid and lead to sloppy coding.
int R;
with color1,color2
R = 1; ' which R is used here?
end with
That's not how With blocks work in VB.NET. They apply to only one
object, and members of that object are prefixed with a period. So:
With color1
.R = 1
End With
a long time ago when I used pascal I also liked this feature but I also saw
that it leads to unreadable and ambigous code. now Iam glad that neither
C/C++ nor Java or C# have such a feature.
VB.NET doesn't have such a feature, either. VB's With mechanism is
neither unreadable nor ambiguous. In fact, I find
Dim myVariable As ListItem = New ListItem
With myVariable
.Text = "New Item"
.ForeColor = Color.Red
.BackColor = Color.LightGray
.Tag = 5
End With
to be more readable than
Dim myVariable As ListItem = New ListItem
myVariable.Text = "New Item"
myVariable.ForeColor = Color.Red
myVariable.BackColor = Color.LightGray
myVariable.Tag = 5
In C#, if you leave a semicolon out the error is instantly
highlighened.
I'm not just talking about syntax errors, I'm talking about all compiler
errors: invalid casts, typos, case mismatches, improper type conversions,
using For Each on an object that doesn't implement IEnumerable, etc. The
minute you type an invalid line, it highlights it for you. These are things
that you have to build your C# project to detect. Not a big deal, of
course, but a helpful little feature that saves some time and teaches you to
avoid those mistakes more effectively.
I appreciate that you like C#, and there's nothing wrong with that.
It's a perfectly decent language. But you seem to have decided that VB.NET
is inferior without actually knowing that much about it. I think it at
least deserves a fair hearing, don't you?
Jeremy