Solved

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

Posted on 2014-11-18
7
482 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 74

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 62

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 74

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
C# Export DataGridView 4 41
Exception in Log4Net 1 20
C# SQL BULK INSERT CLASS 5 36
Convert to Hour/minute textbox and compare 3 36
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now