Solved

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

Posted on 2014-11-18
7
578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 300 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 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 200 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

630 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