# CS5001 error C#

**URL:** <https://forum.codewithmosh.com/t/cs5001-error-c/6315>\
**Category:** Uncategorized\
**Created:** [July 23, 2021, 3:56pm UTC](https://forum.codewithmosh.com/t/cs5001-error-c/6315 "2021-07-23T15:56:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bpiii](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@bpiii](https://forum.codewithmosh.com/u/bpiii)\
**Post date:** [July 23, 2021, 3:56pm UTC](https://forum.codewithmosh.com/t/cs5001-error-c/6315/1 "2021-07-23T15:56:19Z")

</div>

Doing the exercise for The Ultimate C# Series: Part 1 section Working With Text. The solution is as follows, but typing exactly as the solution yields the error code: CS5001: Program does not contain a static ‘Main’ method suitable for an entry point. Can someone suggest a solution? Thank you.

using System;  
using System.Collections.Generic;

namespace CSharp1Exercises  
{  
public class Strings  
{  
///

#  
/// Write a program and ask the user to enter a few numbers separated by a hyphen. Work out  
/// if the numbers are consecutive. For example, if the input is “5-6-7-8-9” or “20-19-18-17-16”,  
/// display a message: “Consecutive”; otherwise, display “Not Consecutive”.  
///   
public void Exercise1()  
{  
Console.Write("Enter a few numbers (eg 1-2-3-4): ");  
var input = Console.ReadLine();

```
        var numbers = new List<int>();
        foreach (var number in input.Split('-'))
            numbers.Add(Convert.ToInt32(number));                

        numbers.Sort();

        var isConsecutive = true;
        for (var i = 1; i < numbers.Count; i++)
        {
            if (numbers[i] != numbers[i - 1] + 1)
            {
                isConsecutive = false;
                break;
            }
        }

        var message = isConsecutive ? "Consecutive" : "Not Consecutive";
        Console.WriteLine(message);
    }
```

---

<div class="post-metadata">

**Author:** ![ammarsaleem1995](https://avatars.discourse-cdn.com/v4/letter/a/71c47a/32.png) [@ammarsaleem1995](https://forum.codewithmosh.com/u/ammarsaleem1995)\
**Post date:** [July 23, 2021, 4:12pm UTC](https://forum.codewithmosh.com/t/cs5001-error-c/6315/2 "2021-07-23T16:12:43Z")

</div>

Add the following Main function in class Strings  
public static void Main(){  
Exercise1();  
}

Then, double click Properties in Solution Explorer, and set the Strings class as Statup project.

---

<div class="post-metadata">

**Author:** ![bpiii](https://avatars.discourse-cdn.com/v4/letter/b/e68b1a/32.png) [@bpiii](https://forum.codewithmosh.com/u/bpiii)\
**Post date:** [July 23, 2021, 4:47pm UTC](https://forum.codewithmosh.com/t/cs5001-error-c/6315/3 "2021-07-23T16:47:31Z")

</div>

Thank you for your response.  
I don’t quite follow your suggestion. Can you please copy and paste the entire text with your changes so that I can see exactly where the changes need to go?  
Also I clicked on the name of the program in Solution Explorer (can’t double click just single click) but I don’t see anything called Startup project. Is there another place where this setting the String class as Startup project be done.

---

<div class="post-metadata">

**Author:** ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)\
**Post date:** [July 24, 2021, 1:52am UTC](https://forum.codewithmosh.com/t/cs5001-error-c/6315/4 "2021-07-24T01:52:25Z")

</div>

C#/.NET programs always need a `Main()` method, which is the method that is called to start your program. So without a `Main()` method, your program doesn’t start!

Try this:

```auto
using System;
using System.Collections.Generic;

namespace CSharp1Exercises
{
    public class Program
    {
        static void Main(string[] args)
        {
            Strings.Exercise1();
        }
    }

    public class Strings
    {
        ///
        /// Write a program and ask the user to enter a few numbers separated by a hyphen. Work out
        /// if the numbers are consecutive. For example, if the input is “5-6-7-8-9” or “20-19-18-17-16”,
        /// display a message: “Consecutive”; otherwise, display “Not Consecutive”.
        ///
        
        public static void Exercise1()
        {
            Console.Write("Enter a few numbers (eg 1-2-3-4): ");
            var input = Console.ReadLine();
            var numbers = new List<int>();
            foreach (var number in input.Split('-'))
                numbers.Add(Convert.ToInt32(number));

            numbers.Sort();

            var isConsecutive = true;
            for (var i = 1; i < numbers.Count; i++)
            {
                if (numbers[i] != numbers[i - 1] + 1)
                {
                    isConsecutive = false;
                    break;
                }
            }

            var message = isConsecutive ? "Consecutive" : "Not Consecutive";
            Console.WriteLine(message);
        }
    }
}

```
