I have the following code:
int iMth = DateTime.Now.Month;
int iYr = DateTime.Now.Year;
string sYear;
string sMonth;
switch (iMth)
{
case 1:
if (iMth == 1)
{
iYr = iYr - 1;
sMonth = "12";
sYear = iYr.ToString();
}
break;
case 2:
if (iMth > 1 || iMth < 10)
{
iMth = iMth - 1;
sMonth = "0" + iMth.ToString();
sYear = iYr.ToString();
}
break;
case 3:
if (iMth >= 10)
{
sMonth = iMth.ToString();
sYear = iYr.ToString();
}
break;
}
iMth is equal to 3 and iYr is equal to 2008. The trouble is that iMth is dropping through the switch statement to case 3 even though iMth is 3. I am relatively new to C# so this is a little troubling to me(C++ was several years ago). Can anyone give me some suggestions? Thanks for all help in advance.
Dave
int iMth = DateTime.Now.Month;
int iYr = DateTime.Now.Year;
string sYear;
string sMonth;
switch (iMth)
{
case 1:
if (iMth == 1)
{
iYr = iYr - 1;
sMonth = "12";
sYear = iYr.ToString();
}
break;
case 2:
if (iMth > 1 || iMth < 10)
{
iMth = iMth - 1;
sMonth = "0" + iMth.ToString();
sYear = iYr.ToString();
}
break;
case 3:
if (iMth >= 10)
{
sMonth = iMth.ToString();
sYear = iYr.ToString();
}
break;
}
iMth is equal to 3 and iYr is equal to 2008. The trouble is that iMth is dropping through the switch statement to case 3 even though iMth is 3. I am relatively new to C# so this is a little troubling to me(C++ was several years ago). Can anyone give me some suggestions? Thanks for all help in advance.
Dave