Inheritance w/ 2 Main() methods in Visual Studio .NET C#
-
I'm currently learning C# and Visual Studio and have run into this problem. I'm reading Petzold's "Programming Windows with C#" and am working with two classes, both of which have Main() methods. The second class, CsDateInheritance, is an inherited class of the first, CsDateConstuctors, and I want the program to use the Main() method of the second class, CsDateInheritance. If using a DOS command line, the program can be complied as such:
C:\(rootfolder)>csc CsDateInheritance.cs CsDateConstructors.cs /main:CsDateInheritance Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4 for Microsoft (R) .NET Framework version 1.1.4322 Copyright (C) Microsoft Corporation 2001-2002. All rights reserved. C:\(rootfolder)> CsDateInheritance.exe Birthday = 21 Aug 1981 Today = 24 Aug 2003 Days since birthday = 8038 C:\(rootfolder)>_
Program works perfectly. Though, I want to be able to run/debug this program in Visual Studio .NET 2003. I'm using the C# Standard Edition. I have the first class file inserted into the solution as a linked file. When I compile in VS .NET, I get a "this program has more than one entry point defined" error. How can I fix this in VS .NET, without having to compile from the command line? I have found that I can set the Main() method of CsDateConstructors "IsShared" value to false, and I get a clean build. Though, this sets the class to basically be "Inheritable" only, and not stand alone. Anyone know the trick? All help/suggestions welcome.
Joe realmrat@msn.com
-
I'm currently learning C# and Visual Studio and have run into this problem. I'm reading Petzold's "Programming Windows with C#" and am working with two classes, both of which have Main() methods. The second class, CsDateInheritance, is an inherited class of the first, CsDateConstuctors, and I want the program to use the Main() method of the second class, CsDateInheritance. If using a DOS command line, the program can be complied as such:
C:\(rootfolder)>csc CsDateInheritance.cs CsDateConstructors.cs /main:CsDateInheritance Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4 for Microsoft (R) .NET Framework version 1.1.4322 Copyright (C) Microsoft Corporation 2001-2002. All rights reserved. C:\(rootfolder)> CsDateInheritance.exe Birthday = 21 Aug 1981 Today = 24 Aug 2003 Days since birthday = 8038 C:\(rootfolder)>_
Program works perfectly. Though, I want to be able to run/debug this program in Visual Studio .NET 2003. I'm using the C# Standard Edition. I have the first class file inserted into the solution as a linked file. When I compile in VS .NET, I get a "this program has more than one entry point defined" error. How can I fix this in VS .NET, without having to compile from the command line? I have found that I can set the Main() method of CsDateConstructors "IsShared" value to false, and I get a clean build. Though, this sets the class to basically be "Inheritable" only, and not stand alone. Anyone know the trick? All help/suggestions welcome.
Joe realmrat@msn.com
Problem solved. Thanks to ericgu @ experts-exchange :-D
You can set this in the project properties.
Look for the "startup object" setting, and enter the name of the class that the Main() method is in.
Joe realmrat@msn.com