Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-11-18
7
Medium Priority
?
661 Views
Last Modified: 2014-11-18
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

0
Comment
Question by:Scarlett72
  • 4
  • 2
7 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1200 total points
ID: 40450452
Your trying to (inadvertently) add the method directly within the constructor. Just move the method declaration:

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

0
 

Author Comment

by:Scarlett72
ID: 40450472
Ok, I think I know what I was doing wrong .... putting the GetFirstDayOfNextMonth in the CalendarClass Method.
0
 
LVL 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 800 total points
ID: 40450476
I think this is what you are looking for. The class CalendarClass has an internal class called CalendarClass. If you are looking for something different please explain what you are looking for.

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

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40450487
To avoid confusion, I wouldn't call a constructor a method  : )
0
 

Author Comment

by:Scarlett72
ID: 40450504
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

0
 

Author Comment

by:Scarlett72
ID: 40450508
Ok, it is working now.  Still trying to understand how everything flows, thank you kaufmed!
0
 

Author Comment

by:Scarlett72
ID: 40450510
...and fernando!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question