S
sck10
Hello, I am trying to get the Month from the following using "switch" in my
App_Code file. The error that I am getting is:
An object reference is required for the nonstatic field, method, or property
'class_General.MonthIndexToString(int)'
In my content page I am using the following syntax to call my class:
int MonthIndex = 4;
string MyMonth = class_General.MonthIndexToString(MonthIndex);
App_Code
------------
public class class_General
{
public class_General()
{
//
//
}
public string MonthIndexToString(int MyMonth)
{
//Get the month from the integer value for the month (January: 1)
string strMyDate = "Non Selected";
switch (MyMonth)
{
case 1: strMyDate = "January";
break;
case 2: strMyDate = "February";
break;
case 3: strMyDate="March";
break;
case 4: strMyDate = "April";
break;
case 5: strMyDate = "May";
break;
case 6: strMyDate = "June";
break;
case 7: strMyDate = "July";
break;
case 8: strMyDate = "August";
break;
case 9: strMyDate = "September";
break;
case 10: strMyDate = "October";
break;
case 11: strMyDate = "November";
break;
case 12: strMyDate = "December";
break;
default: strMyDate = "Non Selected";
break;
} // end switch
return strMyDate;
}
App_Code file. The error that I am getting is:
An object reference is required for the nonstatic field, method, or property
'class_General.MonthIndexToString(int)'
In my content page I am using the following syntax to call my class:
int MonthIndex = 4;
string MyMonth = class_General.MonthIndexToString(MonthIndex);
App_Code
------------
public class class_General
{
public class_General()
{
//
//
}
public string MonthIndexToString(int MyMonth)
{
//Get the month from the integer value for the month (January: 1)
string strMyDate = "Non Selected";
switch (MyMonth)
{
case 1: strMyDate = "January";
break;
case 2: strMyDate = "February";
break;
case 3: strMyDate="March";
break;
case 4: strMyDate = "April";
break;
case 5: strMyDate = "May";
break;
case 6: strMyDate = "June";
break;
case 7: strMyDate = "July";
break;
case 8: strMyDate = "August";
break;
case 9: strMyDate = "September";
break;
case 10: strMyDate = "October";
break;
case 11: strMyDate = "November";
break;
case 12: strMyDate = "December";
break;
default: strMyDate = "Non Selected";
break;
} // end switch
return strMyDate;
}