Reputation: 35597
Why does the structure between console application seem so different between C#
and VB.NET
?
In C#
I often create an instance of the Program class:
namespace ConsoleApplicationX {
class Program {
static void Main(string[] args) {
Program p;
p = new Program();
...
...
In a VB.NET
example I have Main
located in a file called __ZooWork.vb
like the following:
Module __ZooWork
Sub Main()
...
...
Can I do an equivalent implementation to the C#
code above in VB.NET
?
EDIT
I've tried the following but it errors:
FURTHER EDIT
Just to confirm a couple of settings - these don't seem to have solved it!...
Upvotes: 0
Views: 509
Reputation: 149050
Those are just the templates you can use when starting a new project. Of course you can write the equivalent code in both languages.
Namespace ConsoleApplicationX
Class Program
Shared Sub Main()
Dim p As New Program()
...
End Sub
End Class
End Namespace
Upvotes: 4
Reputation: 203829
You probably shouldn't be creating an instance of the type your entry point is in to begin with. While it's certainly possible in either language, it's not good design in either.
Just have your Main
method create an instance of some other type, not the type that Main
itself is in, and use that for your program logic.
As for the error:
Program [...] does not contain a static 'Main' method suitable for an entry point
That's because your Main
method isn't of the proper signature. It should be:
Shared Sub Main()
End Sub
The Shared
is important (it's the equivalent of static
in C#; it indicates that you do not need an instance of that type to call the method, which is important for the entry point as it won't have an instance of the type before the program is started.
Upvotes: 1