Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Inheritance w/ 2 Main() methods in Visual Studio .NET C#

Inheritance w/ 2 Main() methods in Visual Studio .NET C#

Scheduled Pinned Locked Moved C#
helpcsharpvisual-studioquestiondotnet
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Joe McBride
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • J Joe McBride

      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

      J Offline
      J Offline
      Joe McBride
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups