最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - More than one entry point defined? - Stack Overflow

programmeradmin5浏览0评论

Every time I try to use the code in the code editor for our textbook it says there is more than one entry point defined. But when I use it in Visual Studio it works perfectly fine.

using System;
using static System.Console;
using System.Globalization;
class ProjectedRaises
{
    static void Main()
    {
    
        const double RAISE = .04;
        string salaryAsString;
        double salary;
        double total;

        Write("Enter employee salary: ");
        salaryAsString = ReadLine();
        salary = Convert.ToDouble(salaryAsString);
        total = salary + (salary * RAISE);

        WriteLine("Next year's salary for the first employee will be {0}", 
        total.ToString("C", CultureInfo.GetCultureInfo("en-US")));
    
    }
}

It is the code editor for "Cengage MindTap Microsoft Visual C#" textbook. It provides all the stuff at the top and the Main and all the curly brackets. I just have to write the stuff in between. The code I posted is the whole thing that is in the window.

Every time I try to use the code in the code editor for our textbook it says there is more than one entry point defined. But when I use it in Visual Studio it works perfectly fine.

using System;
using static System.Console;
using System.Globalization;
class ProjectedRaises
{
    static void Main()
    {
    
        const double RAISE = .04;
        string salaryAsString;
        double salary;
        double total;

        Write("Enter employee salary: ");
        salaryAsString = ReadLine();
        salary = Convert.ToDouble(salaryAsString);
        total = salary + (salary * RAISE);

        WriteLine("Next year's salary for the first employee will be {0}", 
        total.ToString("C", CultureInfo.GetCultureInfo("en-US")));
    
    }
}

It is the code editor for "Cengage MindTap Microsoft Visual C#" textbook. It provides all the stuff at the top and the Main and all the curly brackets. I just have to write the stuff in between. The code I posted is the whole thing that is in the window.

Share Improve this question asked Feb 5 at 9:13 RLARLA 254 bronze badges 4
  • Does that Code Editor have a notion of "Solution" and / or "Project"s? Usually you should not post images, but maybe in this case it could help to see a screenshot, so we see what you see. Because I think only a handfull of people would be familiar with that specific editor and book. – Fildor Commented Feb 5 at 9:14
  • 4 Every time I try to use the code in the code editor for our textbook - probably the code editor generates some extra stuff for you which leads to second Main generated. – Guru Stron Commented Feb 5 at 9:18
  • Are you on a auto-didactic journey or is this part of a course? (Where in the latter you could maybe ask your teacher?) – Fildor Commented Feb 5 at 9:19
  • is there perhaps a Program.cs somewhere that also has an entry-point? This could be a second Main() method, but it could also just be "top-level statements", for example Console.WriteLine("Hello, World!"); not inside a type (that example is taken directly from the default Program.cs at the time of writing). The first thing I'd do here is rename Main to Main2 so it compiles, run it, and see what happens; if I get a text console message: I'd search the code for that message. If this is caused by a Program.cs: presumably just delete that file. – Marc Gravell Commented Feb 5 at 10:26
Add a comment  | 

1 Answer 1

Reset to default 0

Your

static void Main()

is an entry point. You are being told there is another. So you will need to search for static void Main( or Main( in your Cengage MindTap Microsoft Visual C# textbook. If you don't find it, debug your application and see where it gets you first. That's the other entry point.

Of course, you will need to temporarily rename your Main to Main2 for the time being to find the other entry point. Then adjust your main entry point with the content you intended to have inside your entry point.

发布评论

评论列表(0)

  1. 暂无评论