当前位置: 首页>>代码示例>>C#>>正文


C# Teacher.SetInformationFromInput方法代码示例

本文整理汇总了C#中Teacher.SetInformationFromInput方法的典型用法代码示例。如果您正苦于以下问题:C# Teacher.SetInformationFromInput方法的具体用法?C# Teacher.SetInformationFromInput怎么用?C# Teacher.SetInformationFromInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Teacher的用法示例。


在下文中一共展示了Teacher.SetInformationFromInput方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main()
        {
            #region object definition
            Person student = new Student();
            student.SetInformationFromInput();
            student.PrintDetails();

            Person teacher = new Teacher();
            teacher.SetInformationFromInput();
            teacher.PrintDetails();

            UProgram uProgram = new UProgram();
            uProgram.SetInformationFromInput();
            uProgram.PrintDetails();

            Course course = new Course();
            course.SetInformationFromInput();
            course.PrintDetails();
            #endregion

            #region call method with NotImplementedException
            DateTime birthDate;
            string birthDateString = "12/01/1900"; // mm/dd/yyyy
            student.ValidatePersonBirthdate(birthDateString, out birthDate);
            #endregion
        }
开发者ID:CptDemocracy,项目名称:edx_dev204x,代码行数:26,代码来源:module3_code.cs

示例2: SetInformationFromInput

        public void SetInformationFromInput()
        {
            const string COURSE_NAME_USER_PROMPT       = "Please enter the course name:       ";
            const string CREDITS_USER_PROMPT           = "Please enter the number of credits: ";
            const string DURATION_IN_WEEKS_USER_PROMPT = "Please enter the duration in weeks: ";
            const string TEACHER_INFO_USER_PROMPT      = "Please enter information about course's teacher. ";

            /*
                    If it throws during input gathering, we want to make
                    sure, our Student object will not be corrupted.
                    We could define new variables to save user input to,
                    and then after we were fairly confident that input was
                    good to go, we would set it to object's fields, however...

                    But what if, though highly unlikely, setters throw?
                    That would leave our object half-mutated and with corrupt
                    data. Fortunately, we can pay the price of caching
                    object's fields and simply restore object's values in
                    the catch block if something does go wrong. Hence,
                    no need to define new variables just to collect user data.
               */

            string  nameFieldCopy            = Name;
            int     creditsFieldCopy         = Credits;
            int     durationInWeeksFieldCopy = DurationInWeeks;

            try
            {

                #region input gathering

                Console.WriteLine(COURSE_NAME_USER_PROMPT);
                Name = Console.ReadLine();

                Console.WriteLine(CREDITS_USER_PROMPT);
                Credits = Int32.Parse( Console.ReadLine() );

                Console.WriteLine(DURATION_IN_WEEKS_USER_PROMPT);
                DurationInWeeks = Int32.Parse( Console.ReadLine() );

                Console.WriteLine(TEACHER_INFO_USER_PROMPT);

                // delegate input collection and data restoration on throw
                // for Teacher to Teacher's own method
                Teacher = new Teacher();
                Teacher.SetInformationFromInput();

                #endregion

            }
            catch {

                #region restoring fields

                Name = nameFieldCopy;
                Credits = creditsFieldCopy;
                DurationInWeeks = durationInWeeksFieldCopy;
                // Teacher restoration is delegated to its own SetInformationFromInput method

                #endregion

                throw;
            }
        }
开发者ID:CptDemocracy,项目名称:edx_dev204x,代码行数:64,代码来源:module3_code.cs


注:本文中的Teacher.SetInformationFromInput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。