Copying and Pasting cs Code
In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.
For example, you can follow the pattern in this listing: private void getData(int Rows)
{
List lst = new List();
lst = readfile("datadoan.txt");
if (Rows >= lst.Count)
{
Rows = iRows = lst.Count - sodonghienlen;
}
else if (Rows <= 0)
{
Rows = iRows = 0;
}
//if + else kiểm tra đã load hết file text chưa nếu hết thì khi nhấn next sẽ k hiện ra gì nữa
for (int i = 0; i < sodonghienlen; i++)
{
string strTemp = "";
if ((Rows + i) < lst.Count)
{
strTemp = lst[Rows + i].ToString();
}
switch (i)
{
case 0:
lbcauhoi.Text = strTemp;
break;
case 1:
checkBox1.Text= strTemp;
checkBox1.Checked = false;
break;
case 2:
checkBox2.Text = strTemp;
checkBox2.Checked = false;
break;
case 3:
checkBox3.Text = strTemp;
checkBox3.Checked = false;
break;
case 4:
checkBox4.Text = strTemp;
checkBox4.Checked = false;
break;
default:
lbd.Text = strTemp;
break;
}
}
}
{
List
lst = readfile("datadoan.txt");
if (Rows >= lst.Count)
{
Rows = iRows = lst.Count - sodonghienlen;
}
else if (Rows <= 0)
{
Rows = iRows = 0;
}
//if + else kiểm tra đã load hết file text chưa nếu hết thì khi nhấn next sẽ k hiện ra gì nữa
for (int i = 0; i < sodonghienlen; i++)
{
string strTemp = "";
if ((Rows + i) < lst.Count)
{
strTemp = lst[Rows + i].ToString();
}
switch (i)
{
case 0:
lbcauhoi.Text = strTemp;
break;
case 1:
checkBox1.Text= strTemp;
checkBox1.Checked = false;
break;
case 2:
checkBox2.Text = strTemp;
checkBox2.Checked = false;
break;
case 3:
checkBox3.Text = strTemp;
checkBox3.Checked = false;
break;
case 4:
checkBox4.Text = strTemp;
checkBox4.Checked = false;
break;
default:
lbd.Text = strTemp;
break;
}
}
}