Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I pass an int parameter to function and I get CS1503 error

public static void draw(int month)
{
    switch (month)
    {
        //assign correct number of days to a month
    };
    for (int day = 1; day <= days; day++)
    {
        public int weekday = new DateTime(year, month, day);
    }
}

I don’t know if I am blind or dumb but for some reason, when I pass month parameter as int, it gets recognized as string in the datetime object initialization.
enter image description here

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I can see from screen that you’re working in Calendar class. As you can see when you’re creating new DateTime(…) it doesn’t take month as variable, but it takes static member field called month. You would need to rename this static field, or the variable itself.

Additionally you need to adjust creation of datetime variable:

  1. It’s datetime, not int
  2. It’s local variable – doesn’t require public. OR, if you wanted to edit static field in class remove public int at all

so can be

DateTime weekday = new DateTime(year, month, day);

or

var weekday = new DateTime(year, month, day);

or (if static field)

weekday = new DateTime(year, month, day);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading