C#에서 SharePoint 웹 파트에 대한 사용자 지정 코드를 만들고 있습니다. 특히, 나는 질문을하고, 대답을하고, 답을 정하는 목록을 다루는 여기에서 중요한 요점 인 퀴즈를 만들고있다.가장 효율적인 C# SharePoint 목록 반복
퀴즈의 마지막 단계에서 나는 사용자가 선택한 답변을 목록의 정답과 대조해야합니다. 현재, 각 질문이 반복되는지 확인하기 위해 각각이 정확한지 확인하기 위해 다음을 수행하고 있습니다. 이는 매우 효율적이지 않다고 가정합니다. SPList foreach 루프에 대한 메서드가 더 효율적입니까?
// 1. Store questions and answers in class
List<submittedAnswers> answeredQuestions = new List<submittedAnswers>();
// 2. From POST pull answered question IDs and answer IDs (which correspond to the question primary key and answer choice number both stored in the list)
// INSERT BEAUTFIUL AND EFFICIENT WHILE LOOP HERE
// 3. Loop through each question is list, if question was given, test if correct/incorrect
using (SPWeb myWeb = mySite.OpenWeb())
{
SPList answerList = myWeb.Lists[questionList];
foreach (SPListItem quizEntry in answerList.Items)
{
int pullAnswerId = int.Parse(quizEntry["Answer"].ToString()); // Pull answer number from list
int pullQuestionId = int.Parse(quizEntry["ID"].ToString()); // Pull primary key of question
submittedAnswers result = answeredQuestions.Find(delegate(submittedAnswers e) { return e.questionId == int.Parse(quizEntry["ID"].ToString()); });
if (result != null)
{
if (result.responseId != pullAnswerId) // If the response was different from the answer
incorrectAnswers++;
else
correctAnswers++;
}
}
}
// C# quiz grading magic here....
이 코드는 어디에 실행됩니까 (이벤트 수신자? webpart?) 매번 각 퀴즈를 채점하지 않으려 고합니까? 왜 당신이 최적화를 시도하는지 확신하지 못합니다. –
퀴즈는 웹 파트에서 실행 중입니다. 두 가지 문제가 있습니다. 1. 퀴즈를 풀면 아마 스파이크가 수백명이 걸릴 수 있습니다. 병목 현상을 최소화합니다. 2. 이것은 내가해온 첫 번째 ASP.NET 프로그래밍이며, 주로 PHP로 작업하기 때문에 OO 디자인과 프로그래밍으로 인해 저를 포기합니다. 또한 목록을 반복하는 방법이 매우 비효율적이라고 말하는 몇 가지 블로그를 읽었습니다. –
"질문"목록에 퀴즈에 나오는 질문이 모두 포함되어 있고 각 사용자의 답변을 확인해야하는 경우 foreach가 정상이라고 말하고 싶습니다. –