C# 如何读取文本文件而不是使用案例?
我正在做一个在文本框中显示问题的项目。在每一个复选框下面有4个复选框,用户必须选择回答问题的复选框 有没有办法把我所有的问题、答案等放在一个.txt文件中,然后从那里加载? 我不想为每个问题都写一个C# 如何读取文本文件而不是使用案例?,c#,checkbox,multiple-choice,C#,Checkbox,Multiple Choice,我正在做一个在文本框中显示问题的项目。在每一个复选框下面有4个复选框,用户必须选择回答问题的复选框 有没有办法把我所有的问题、答案等放在一个.txt文件中,然后从那里加载? 我不想为每个问题都写一个案例(我大约有120个问题) 到目前为止,我的做法是: case 5: // Multiple Answers txtQuestion.Text = "What are the characteristics of the " +
案例
(我大约有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;
一种简单的方法是:
[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>
假设您编写代码并在字符串中包含反斜杠,编译器。。。。
回答
回答
回答
回答
另一个问题。。。。
回答
回答
回答
回答
更好:使用数据库;)是的,有-试一试,让我们知道一个具体的问题,因为目前这个问题太广泛了,无法回答。有太多可能的解决方案。您也可以考虑一个XML文件。你可以有“问题”元素和“回答”元素。为此,我不能使用数据库,这是不允许的。此人明确要求不要使用数据库(不知道为什么他不会使用数据库,因为这样会更好,但是嘿!)。我实际上是想把问答和可能的评论放在一个文本文件中。这可能吗?如果不能使用数据库,请使用XML