你为什么要这样建模?在我看来,下面的例子更有说服力。
[Serializable]
public class HighScoreData
{
public string PlayerName;
public int Score;
public int Level;
}
[Serializable]
public class HighScoresCollection
{
List<HighScoreData> HighScores;
}
然后,当您序列化 highScore 时,您会得到如下内容:
<HighScoresCollection>
<HighScoreData>
<PlayerName>Rocco</PlayerName>
<Score>100</Score>
<Level>1</Level>
</HighScoreData>
<HighScoreData>
<PlayerName>Shawn</PlayerName>
<Score>200</Score>
<Level>2</Level>
</HighScoreData>
<HighScoreData>
<PlayerName>Derrick</PlayerName>
<Score>300</Score>
<Level>3</Level>
</HighScoreData>
</HighScoresCollection>
好吧,HighScoresCollection
在我的示例中对课程的需求是有争议的,你可以只拥有一个分数列表,IMO。