Если вы измените свой Enum следующим образом:
[Flags]
public enum DayOfWeek
{
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6
}
Вы можете попробовать это:
class Program
{
public static bool Equal(DayOfWeek mine, System.DayOfWeek cSharp)
{
int mineInt = (int)mine;
int cSharpInt = (int)cSharp;
return mineInt == cSharpInt;
}
static void Main(string[] args)
{
DateTime dateTime = DateTime.Now;
DayOfWeek dayOfWeek = DayOfWeek.Sunday;
bool areEqual = Equal(dayOfWeek, dateTime.DayOfWeek);
Console.WriteLine(areEqual);
Console.ReadKey();
}
}
Если вы не можете изменить свой Enum, вы можете попробовать это:
class Program
{
public static bool Equal(DayOfWeek mine, System.DayOfWeek cSharp)
{
if (mine == DayOfWeek.Friday && cSharp == System.DayOfWeek.Friday ||
mine == DayOfWeek.Monday && cSharp == System.DayOfWeek.Monday ||
mine == DayOfWeek.Saturday && cSharp == System.DayOfWeek.Saturday ||
mine == DayOfWeek.Sunday && cSharp == System.DayOfWeek.Sunday ||
mine == DayOfWeek.Thursday && cSharp == System.DayOfWeek.Thursday ||
mine == DayOfWeek.Tuesday && cSharp == System.DayOfWeek.Tuesday ||
mine == DayOfWeek.Wednesday && cSharp == System.DayOfWeek.Wednesday)
return true;
return false;
}
static void Main(string[] args)
{
DateTime dateTime = DateTime.Now;
DayOfWeek dayOfWeek = DayOfWeek.Tuesday;
bool areEqual = Equal(dayOfWeek, dateTime.DayOfWeek);
Console.WriteLine(areEqual);
Console.ReadKey();
}
}