我在驗證用戶名複選框,以查看輸入的值是否存在於XML文件中。驗證XML文件中的值
點擊按鈕時,它應該檢查輸入的名稱是否存在於XML文件中,然後繼續,如果沒有,應該出現消息框。
當前的代碼顯示由於其保護級別,txt_Username.Text = Pupil.forename無法訪問。
在按鈕點擊:
private void btnNext_Click(object sender, RoutedEventArgs e, Pupil p)
{
if (txt_Username.Text = Pupil.forename)
{
this.Hide();
Display nw = new Display(theClass);
nw.ShowDialog();
this.Show();
}
MessageBox.Show("Cannot Find username");
}
瞳類:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PassingData
{
public class Pupil
{
private string forename;
private int score;
public Pupil(string forename, int score)
{
this.forename = forename;
this.score = score;
}
public Pupil()
{
this.forename = "Unknown";
}
public string Forename
{
get { return forename; }
set { forename = value; }
}
public int Score
{
get { return score; }
set { score = value; }
}
override public string ToString()
{
string output = forename + "\t" + score;
return output;
}
}
}
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfPupil xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Pupil>
<Forename>Andy</Forename>
<Score>0</Score>
</Pupil>
<Pupil>
<Forename>Bob</Forename>
<Score>10</Score>
</Pupil>
<Pupil>
<Forename>Carl</Forename>
<Score>20</Score>
</Pupil>
<Pupil>
<Forename>Dave</Forename>
<Score>30</Score>
</Pupil>
<Pupil>
<Forename>Eric</Forename>
<Score>40</Score>
</Pupil>
<Pupil>
<Forename>Frank</Forename>
<Score>50</Score>
</Pupil>
</ArrayOfPupil>
因此改變用名字來公開? 靜態類怎麼樣? – WibblyWobbly 2013-03-28 02:12:04
@MattMeadows:您無法直接訪問非靜態成員,而無需創建實例。 – 2013-03-28 02:16:49
請問您可以在第3點展開? – WibblyWobbly 2013-03-28 02:17:36