Link to home
Start Free TrialLog in
Avatar of Scarlett72
Scarlett72

asked on

Type or namespace definition, or end-of-file expected error on class create

Hi, I am trying to create a class; however, when I add the code for the GetFirstDayOfNextMonth method I receive an error on the last curly brace, it looks like all my braces match and not sure why I am getting this error.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class CalendarClass
{
    public CalendarClass()
    {        
        protected DateTime GetFirstDayOfNextMonth(int setYear, int setMonth)
        {           
            DateTime lastDate = new DateTime(setYear, setMonth, 1);
            return lastDate;
        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scarlett72
Scarlett72

ASKER

Ok, I think I know what I was doing wrong .... putting the GetFirstDayOfNextMonth in the CalendarClass Method.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To avoid confusion, I wouldn't call a constructor a method  : )
Ah, ok thank you kaufmed ... as you can probably tell, this is my first attempt a creating a class, so your attention is truly appreciated.  I posted my comment without seeing yours first.  So now I have moved the outside of the constructor, and now I want to use the method GetFirstDayOfNextMonth in by code behind.  I can write successfully:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class calClass
{
	public calClass()
	{		
	}
    public DateTime GetFirstDayofCurrentMonth()
    {       
        DateTime firstDate = new DateTime(2014, 1, 1);
        return firstDate;
    }
}

Open in new window

calClass cc = new calClass();

Open in new window


but that doesn't do anything, shouldn't I be able to call the method as:

cc.GetFirstDayofCurrentMonth()

Open in new window

Ok, it is working now.  Still trying to understand how everything flows, thank you kaufmed!
...and fernando!