示例#1
0
 static void Main(string[] args)
 {
     Console.WriteLine("Please enter the current day of the week");
     try
     {
         String        dayString = Console.ReadLine();
         DaysOfTheWeek dayValue  = (DaysOfTheWeek)Enum.Parse(typeof(DaysOfTheWeek), dayString, true);
         if (Enum.IsDefined(typeof(DaysOfTheWeek), dayValue) | dayValue.ToString().Contains(","))
         {
             Console.WriteLine("Converted '{0}' to {1}.", dayString, dayValue.ToString());
         }
         else
         {
             Console.WriteLine("Please enter an actual day of the week.");
         }
     }
     catch (ArgumentException)
     {
         Console.WriteLine("Please enter an actual day of the week.");
     }
     finally
     {
         Console.ReadLine();
     }
 }
 public static string Format(DaysOfTheWeek day)
 {
     DisplayNameAttribute[] attribute =
         (DisplayNameAttribute[])typeof(DaysOfTheWeek).GetField(
             day.ToString())
         .GetCustomAttributes(typeof(DisplayNameAttribute), false);
     return attribute.Count() == 0 ?
         day.ToString() : attribute.FirstOrDefault().Name;
 }
示例#3
0
 public static string Format(DaysOfTheWeek day)
 {
     DisplayNameAttribute[] attribute =
         (DisplayNameAttribute[])typeof(DaysOfTheWeek).GetField(
             day.ToString())
         .GetCustomAttributes(typeof(DisplayNameAttribute), false);
     return(attribute.Count() == 0 ?
            day.ToString() : attribute.FirstOrDefault().Name);
 }
示例#4
0
        static void Main(string[] args)
        {
            Weeks week = new Weeks();

            week.DaysOfTheWeek = new DaysOfTheWeek();

            Console.WriteLine("what day of the week is it? ");


            bool input = false;

            while (input == false)
            {
                try
                {
                    DaysOfTheWeek today = (DaysOfTheWeek)Enum.Parse(typeof(DaysOfTheWeek), Console.ReadLine(), true);
                    Console.WriteLine("You think today is: {0}", today.ToString());
                    input = true;
                }
                catch (Exception)
                {
                    Console.WriteLine("Please enter an actual day of the week:");
                }
            }
            Console.ReadLine();
        }
示例#5
0
        public void GetAttribute_OnDaysOfTheWeek_Success()
        {
            DaysOfTheWeek day = DaysOfTheWeek.Monday;
            Assert.AreEqual<string>("Monday", day.ToString());

            Assert.AreEqual<string>("MONDAY",
                DisplayNameAttribute.Format(day));
        }
示例#6
0
        public void GetAttribute_NoAttribute_Success()
        {
            DaysOfTheWeek day = DaysOfTheWeek.Tuesday;
            Assert.AreEqual<string>("Tuesday", day.ToString());

            Assert.AreEqual<string>("Tuesday",
                DisplayNameAttribute.Format(day));

        }
    private void SetWeekDays(DataRow dr, DaysOfTheWeek weekDay, DaysOfTheWeek days)
    {
        string column = "S" + weekDay.ToString();

        if ((weekDay & days) == weekDay)
        {
            dr[column] = 1;
        }
        else
        {
            dr[column] = 0;
        }
    }
    private void AddDay(DataRow dr, DaysOfTheWeek weekDay)
    {
        string column = "S" + weekDay.ToString();

        if (dr[column].ToString() == "1")
        {
            if (triggerDays == 0)
            {
                triggerDays = weekDay;
            }
            else
            {
                triggerDays = triggerDays | weekDay;
            }
        }
    }
示例#9
0
 static void Main(string[] args)
 {
     try
     {
         Console.WriteLine("Enter day of the week.  Example: Monday");
         DaysOfTheWeek value = (DaysOfTheWeek)Enum.Parse(typeof(DaysOfTheWeek), Console.ReadLine());
         Console.WriteLine("The day you entered is: " + value.ToString());
     }
     catch (Exception ex)
     {
         Console.WriteLine("Please enter an actual day of the week");
     }
     finally
     {
         Console.ReadLine();
     }
 }
        static void Main(string[] args)
        {
            Weeks week = new Weeks();

            week.DaysOfTheWeek = new DaysOfTheWeek();

            Console.WriteLine("what day of the week is it? ");


            bool input = false;

            while (input == false)
            {
                try
                {
                    DaysOfTheWeek today = (DaysOfTheWeek)Enum.Parse(typeof(DaysOfTheWeek), Console.ReadLine(), true);
                    Console.WriteLine("You think today is: {0}", today.ToString());
                    input = true;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Please enter an actual day of the week:");
                }
            }


            //Weeks week = new Weeks();
            //week.DaysOfTheWeek = new DaysOfTheWeek();

            //Console.WriteLine("what day of the week is it? ");
            //string GuessDay = Console.ReadLine();


            //try
            //{
            //    DaysOfTheWeek days = (DaysOfTheWeek)Enum.Parse(typeof(DaysOfTheWeek), GuessDay);
            //    switch (GuessDay)
            //    {
            //        case "Monday":
            //            Console.WriteLine("{0} = {1:D} ", GuessDay, Enum.Parse(typeof(DaysOfTheWeek), days.ToString()));
            //            break;
            //        case "Tuesday":
            //            Console.WriteLine("{0} = {1:D} ", GuessDay, Enum.Parse(typeof(DaysOfTheWeek), days.ToString()));
            //            break;
            //        case "Wednesday":
            //            Console.WriteLine("{0} = {1:D} ", GuessDay, Enum.Parse(typeof(DaysOfTheWeek), days.ToString()));
            //            break;
            //        case "Thursday":
            //            Console.WriteLine("{0} = {1:D} ", GuessDay, Enum.Parse(typeof(DaysOfTheWeek), days.ToString()));
            //            break;
            //        case "Friday":
            //            Console.WriteLine("{0} = {1:D} ", GuessDay, Enum.Parse(typeof(DaysOfTheWeek), days.ToString()));
            //            break;
            //        case "Saturday":
            //            Console.WriteLine("{0} = {1:D} ", GuessDay, Enum.Parse(typeof(DaysOfTheWeek), days.ToString()));
            //            break;
            //        case "Sunday":
            //            Console.WriteLine("{0} = {1:D} ", GuessDay, Enum.Parse(typeof(DaysOfTheWeek), days.ToString()));
            //            break;
            //        default:
            //            Console.WriteLine("Please enter an actual day of the week. ");
            //            break;


            //    }
            //    Console.ReadLine();

            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("Please enter an actual day of the week. \n ", ex);


            // testing it gives an exception it cant find the incorrectly spelled stuff
            //DaysOfTheWeek days = (DaysOfTheWeek)Enum.Parse(typeof(DaysOfTheWeek), GuessDay);
            //if (Enum.IsDefined(typeof(DaysOfTheWeek), days) | days.ToString().Contains(GuessDay))
            //{
            //    Console.WriteLine("{0} = {1:D} ", GuessDay, Enum.Parse(typeof(DaysOfTheWeek), days.ToString()));
            //}
            //else
            //{
            //    Console.WriteLine("Please enter an actual day of the week. ");

            //}



            //this one keeps iterating and prints all 7 days and it prints values.
            //foreach (string cname in Enum.GetNames(typeof(DaysOfTheWeek)))
            //{

            //    try
            //    {
            //        DaysOfTheWeek days = (DaysOfTheWeek)Enum.Parse(typeof(DaysOfTheWeek), GuessDay);
            //        if (Enum.IsDefined(typeof(DaysOfTheWeek), days) | days.ToString().Contains(","))
            //            Console.WriteLine("{0} = {1:D} ", GuessDay, Enum.Parse(typeof(DaysOfTheWeek), days.ToString()));
            //        else
            //            Console.WriteLine("Please enter an actual day of the week. ");
            //    }
            //    catch (Exception ex)
            //    {
            //        Console.WriteLine(ex);
            //    }



            // practice but it prints out all 7  but print the value a left or right bool. it doesnt work

            //int vale = Convert.ToInt32(week.DaysOfTheWeek);
            //foreach (var cname in Enum.GetNames(typeof(DaysOfTheWeek))) ;
            //{
            //    try
            //    {

            //        DaysOfTheWeek days = (DaysOfTheWeek)Enum.Parse(typeof(DaysOfTheWeek), GuessDay);
            //        if (Enum.IsDefined(typeof(DaysOfTheWeek), days) || days.ToString().Contains(","))
            //            Console.WriteLine("Your selection '{0}' is {1}.", GuessDay, days.ToString());
            //        else
            //            Console.WriteLine("Please enter an actual day of the week. ");
            //    }


            //    catch (Exception ex)
            //    {
            //        Console.WriteLine(ex);
            //    }

            //}


            Console.ReadLine();
        }
示例#11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the day of the week: ");

            try
            {
                DaysOfTheWeek daySelect = (DaysOfTheWeek)Enum.Parse(typeof(DaysOfTheWeek), Console.ReadLine());
                foreach (string day in Enum.GetNames(typeof(DaysOfTheWeek)))
                {
                    Console.WriteLine("{0} = {1:D}", day, Enum.Parse(typeof(DaysOfTheWeek), day));
                }
                Console.WriteLine("You entered: " + "{0} = {1:D}", daySelect, Enum.Parse(typeof(DaysOfTheWeek), daySelect.ToString()));
            }
            catch (Exception)
            {
                Console.WriteLine("Please enter an actual day of the week: ");
            }
            Console.ReadLine();
        }