Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about classes

Status
Not open for further replies.

fluxdemon

MIS
Nov 5, 2002
89
0
0
US
I get the error "Calendar.Date.CV_SELECTEDMONTH denotes a field where a class was expected" when I am trying to use a private variable inside a class:

private DateTime CV_SELECTEDMONTH=DateTime.Today;

private int CV_DAYSSELCTEDMONTH=DateTime.DaysInMonth(CV_SELECTEDMONTH.Year,CV_SELECTEDMONTH.Month);
 
I think the problem you're experiencing is because you're trying to declare your variable and instantiate the object in the same line, and for some reason, the compiler is not creating the CV_SELECTED month object before it is executing the code to retreive the DaysInMonth.

I just created a project, copied your code and received the same error. BUT when I moved the instantiation to either a class constructor, or the Form_Load event, everything worked fine.

Also, if you want to clean it up a little, you don't have to create CV_SELECTEDMONTH. You'd get the same thing by using ...

private int CV_DAYSELECTEDMONTH=DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);

______________________________________________
When told, "goto hell", a programmer finds the method, not the destination as harmful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top