2014-05-09 3 views
-1

저는 텍스트 상자에 질문을 표시하는 프로젝트를 진행하고 있습니다. 그들 각자의 밑에 4 개의 체크 박스가 있고 사용자는 질문에 응답하는 것을 선택해야합니다.사례를 사용하는 대신 텍스트 파일을 읽는 방법은 무엇입니까?

모든 질문, 답변 등을 .txt 파일에 넣고 거기에서로드 할 수있는 방법이 있습니까? 각 질문마다 약 case을 쓰고 싶지 않습니다 (약 120 개의 질문이 있습니다).

지금까지 그 일을 내 방식 :

case 5: // Multiple Answers 
       txtQuestion.Text = "What are the characteristics of the " + 
            "Main method? (Choose two)"; 

       grpSingleChoice.Visible = false; 
       grpMultipleChoice.Visible = true; 

       chkAnswer1.Text = "A. It must always return void"; 
       chkAnswer2.Text = "B. It is always the first method inside the " + 
            "main class of a program"; 
       chkAnswer3.Text = "C. It is the start and end point of a program"; 
       chkAnswer4.Text = "D. It must always be passed an array of strings " + 
            "as in static void Main(string[] args)"; 
       chkAnswer5.Visible = true; 
       chkAnswer5.Text = "E. It must be created inside of a class" + 
            "or a structure"; 
       break; 
+2

더 나은 : 사용 데이터베이스) –

+0

예있다 - 갈을 가지고 우리가 특정 질문을 알려 때문에 너무 광범위 순간에 대답 할 수있는 질문에. 가능한 해결책이 너무 많습니다. – Ian

+0

XML 파일을 고려할 수도 있습니다. "질문"요소와 "대답"요소를 가질 수 있습니다. –

답변

1

이 일을하는 간단한 방법은 다음과 같습니다

[START] 
Question = Imagine you write code and include a backslash in a string, the compiler ... 
Correct = 2 
Option = Answer a 
Option = Answer b 
Option = Answer c 
Option = Answer d 
[END] 

은 "태그"그래서 그냥에 Split(lineText, " = ")를 사용, 루프 조건이 될 것입니다

값을 얻으십시오. 그러나 XML이 훨씬 더 나은 솔루션입니다 :

<xml> 
    <question correct="2"> 
     <description>Imagine you write code and include a backslash in a string, the compiler ....</description> 
     <option>answer</option> 
     <option>answer</option> 
     <option>answer</option> 
     <option>answer</option> 
    </question> 
    <question correct="3"> 
     <description>Another question....</description> 
     <option>answer</option> 
     <option>answer</option> 
     <option>answer</option> 
     <option>answer</option> 
    </question> 
</xml> 
관련 문제