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"); // } }
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); }
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!"); }
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); }
static CSharp8NullableReferenceTypes() { var x = new SurveyRun(); }