-3
using System;

class HelloWorld
{

    public static int GetYear()
    {
        Console.WriteLine("Please enter year: ");
        int year = Convert.ToInt32(Console.ReadLine());
        return year;
    }

    public static int GetMonth()
    {
        Console.WriteLine("Please enter month number (Febuary is 2): ");
        int month = Convert.ToInt32(Console.ReadLine());
        return month;
    }

    static string GetMonthName(int month)
    {
        string[] monthName = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
        string monthValue = monthName[month - 1];
        return monthValue;
    }

    public static bool LeapYear(int Year)
    {
        if (((Year % 4 == 0) && (Year % 100 != 0)) || (Year % 400 == 0))
            return true;
        else
            return false;
    }

    public static void print(string monthValue, int days, int year, int month)
    {
        Console.WriteLine("{0} {1} has {2} days\n", year, monthValue, days);
    }

    static void Main()
    {
        int[] days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int[] leapDays = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int monthDays;

        while (true)
        {
            int year = GetYear();
            int month = GetMonth();
            if (year > 0 && month > 0 && month <= 12)
            {
                string monthValue = GetMonthName(month);
                bool leap = LeapYear(year);

                if (leap)
                {
                    monthDays = leapDays[month - 1];
                    print(monthValue, monthDays, year, month);
                }
                else
                {
                    monthDays = days[month - 1];
                    print(monthValue, monthDays, year, month);
                }
            }
            else
            {
                Console.WriteLine("Invalid Year or Month entered!! Please enter a correct value");
                break;
            }
        }
    }
}

I kept getting an error in Github actions, the error was "could not find public class name" even though the Main class is capitalized. I don't know what I'm doing wrong here

When using dotnetfiddle as instructed by my teacher, the error message I received was "Public Main() method is required in a public class" but like I mentioned above, making sure the Main function was capitalized did nothing

gunr2171
  • 16,104
  • 25
  • 61
  • 88
  • Was this code double-spaced by accident somehow during the process of posting it to Stack Overflow? – Wyck Nov 13 '22 at 04:49
  • 2
    You didn't read the whole error message. It's says "_Public_ Main() method is required in a public class". Your `Main()` is private because you didn't put `public` in front of it and private is the default. – Etienne de Martel Nov 13 '22 at 04:49

2 Answers2

1

The error message you're receiving is because your Main method is not declared as public. In order for your program to run, the Main method must be declared as public.

To fix this, simply change the declaration of your Main method from:

static void Main()

to:

public static void Main()
Igor
  • 474
  • 2
  • 10
0

could not find the public class name

is Java error, you can refer to this. So it might be the case that your project might be pointing to Java not .Net in GitHub.

And your code is written in C#, I am able to compile and run your code in Visual Studio successfully without making any changes in your code.

The console compilation on .net Fiddle requires that both the class containing the main method and the static main method have to be marked public if you target it in the 4.7.2 version.

Though it's not required if you change it to .net 6.

enter image description here

and if you really want to target lower .net versions then you can simply change the main method to public static void Main()

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197