I am maintaining an application that has both VB.NET and c# components. I thought these two languages differed only in syntax, but I have found a strange feature in VB.NET that is not present in C#.
In VB.NET, I have the following class:
Public Class bill_staff Inherits System.Windows.Forms.Form
....
End Class
If I want to use this class in C#, I do this:
using (var frm = new bill_staff())
frm.ShowDialog();
However, in the VB.NET code, the class can be used like this:
bill_staff.ShowDialog();
ShowDialog
is defined in the metadata like this:
Public Function ShowDialog() As System.Windows.Forms.DialogResult
So in VB.NET, it is possible to call an instance method on the class. As far as I can tell, this seems to implicitly create a new instance of the class, and then calls the method on that object. In C#, this is not possible - static methods must be called on the class, and instance methods must be called on objects.
I can't find any information about this on the Internet. What is the feature called, and is it good practice?
The project was initially converted from VB6 - is it some weird legacy feature?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…