/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/csharp/tutorials/snippets/NullableIntroduction/Program.cs
31 строка
984 B
Bill Wagner
Retire the "What's new in C# 8" article (#32101)
02 ноя 2022, 17:06
Не верифицирован
02 ноя 2022, 17:06
2b52afd
Код
Авторство
О чём код?
using NullableIntroduction; // <SnippetAddQuestions> 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?"); // </SnippetAddQuestions> // <SnippetRunSurvey> surveyRun.PerformSurvey(50); // </SnippetRunSurvey> // <SnippetWriteAnswers> 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).QuestionText} : {answer}"); } } else { Console.WriteLine("\tNo responses"); } } // </SnippetWriteAnswers>