示例#1
0
        static void Main(string[] args)
        {
            var surveyRun = new SurveyRun();

            surveyRun.AddQuestion(QuestionType.YesNo, "Has your code ever thrown a NullReferenceException?");
            surveyRun.AddQuestion(new SurveyQuestion(QuestionType.Number, "How many times (to the nearest 100) has that happened?"));
            surveyRun.AddQuestion(QuestionType.Text, "What is your favorite color?");
            surveyRun.AddQuestion(QuestionType.Text, default);

            surveyRun.PerformSurvey(50);

            // foreach (var participant in surveyRun.AllParticipants)
            // {
            //     Console.WriteLine($"Participant: {participant.Id}:");
            //     if (participant.AnsweredSurvey)
            //     {
            //         for (int i = 0; i < surveyRun.Questions.Count; i++)
            //         {
            //             var answer = participant.Answer(i);
            //             Console.WriteLine($"\t{surveyRun.GetQuestion(i)} : {answer}");
            //         }
            //     }
            //     else
            //         Console.WriteLine("\tNo responses");
            // }
        }
示例#2
0
        public static void Run()
        {
            var surveyRun = new SurveyRun();

            surveyRun.AddQuestion(QuestionType.YesNo, "Has your code ever thrown a NullReferenceException?");
            surveyRun.AddQuestion(new SurveyQuestion(QuestionType.Number, "How many times (to the nearest 100) has that happened?"));
            surveyRun.AddQuestion(QuestionType.Text, "What is your favorite color?");

            surveyRun.AddQuestion(QuestionType.Text, null);
        }
示例#3
0
        static void Main(string[] args)
        {
            var surveyRun = new SurveyRun();

            surveyRun.AddQuestion(QuestionType.YesNo, "Has your code ever thrown a NullReferenceException?");
            surveyRun.AddQuestion(new SurveyQuestion(QuestionType.Number, "How many times (to the nearest 100) has that
happened?"));
            surveyRun.AddQuestion(QuestionType.Text, "What is your favorite color?");
            surveyRun.AddQuestion(QuestionType.Text, default);
            Console.WriteLine("Hello World!");
        }
示例#4
0
        static void Program()
        {
            var surveyRun = new SurveyRun();

            surveyRun.AddQuestion(QuestionType.YesNo, "Has your code ever thrown a NullReferenceException?");
            surveyRun.AddQuestion(new SurveyQuestion(QuestionType.Number, "How many times (to the nearest 100) has that happened?"));
            surveyRun.AddQuestion(QuestionType.Text, "What is your favorite color?");

            //Warning - Cannot covert null literal to non-nullable reference type
            //surveyRun.AddQuestion(QuestionType.Text, null);
            //surveyRun.AddQuestion(QuestionType.Text, default);

            surveyRun.AddAnswer("Orange");
            surveyRun.AddAnswer(null);
        }
示例#5
0
 static CSharp8NullableReferenceTypes()
 {
     var x = new SurveyRun();
 }