Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-11-18
7
Medium Priority
?
624 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 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
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!

 
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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

704 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