/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/csharp/tutorials/snippets/NullableIntroduction/SurveyRun.cs
32 строки
1 KB
Bill Wagner
Retire the "What's new in C# 8" article (#32101)
02 ноя 2022, 17:06
Не верифицирован
02 ноя 2022, 17:06
2b52afd
Код
Авторство
О чём код?
namespace NullableIntroduction; public class SurveyRun { private List<SurveyQuestion> surveyQuestions = new List<SurveyQuestion>(); // <SnippetRunReport> public IEnumerable<SurveyResponse> AllParticipants => (respondents ?? Enumerable.Empty<SurveyResponse>()); public ICollection<SurveyQuestion> Questions => surveyQuestions; public SurveyQuestion GetQuestion(int index) => surveyQuestions[index]; // </SnippetRunReport> public void AddQuestion(QuestionType type, string question) => AddQuestion(new SurveyQuestion(type, question)); public void AddQuestion(SurveyQuestion surveyQuestion) => surveyQuestions.Add(surveyQuestion); // <SnippetPerformSurvey> private List<SurveyResponse>? respondents; public void PerformSurvey(int numberOfRespondents) { int respondentsConsenting = 0; respondents = new List<SurveyResponse>(); while (respondentsConsenting < numberOfRespondents) { var respondent = SurveyResponse.GetRandomId(); if (respondent.AnswerSurvey(surveyQuestions)) respondentsConsenting++; respondents.Add(respondent); } } // </SnippetPerformSurvey> }