내가 더 일반적인 UserData를의 구현을 시작하는 것 그것이 할 수 있도록 다음과 같이 field1 및 field2 대신 여러 필드 유형을 허용하십시오.
<?xml version="1.0" encoding="UTF-8"?>
<UserData>
<Data>
<Field>NAME 1</Field>
<Field>NAME 2</Field>
</Data>
</UserData>
컨테이너는 다음과 같이 수 : 당신로드에 도움이 필요한 경우
[XmlRoot("UserData")]
public class UserDataContainer
{
public UserDataContainer() {...}
// Can be used load and save a list of strings (Field(s) in XML)
[XmlArray("Data"), XmlArrayItem("Field"),Type = typeof(string))]
public List<string> Data = new List<string>();
public static UserDataContainer Load(path){...}
public void Save(path){...}
public List<string> GetFields(){...}
public void SetFields(List<string> Fields){...}
}
/특히이 위키를 확인하실 수 있습니다 데이터를 작성, 그것은 아주 잘 이루어집니다!
Saving and Loading Data, XmlSerializer
당신은 같이 당신이 개 UserData를 파일을로드 할 것이다 : 두에
// Get the contents of the first user data
List<string> CombinedDatas = UserData1.GetFields();
// Combine in the contents of the second user data
// AddRange actually changes the first list (CombinedDatas)
CombinedDatas.AddRange(UserData2.GetFields());
// If you wanted to save out the combined data in a new xml file
UserDataContainer FinalData = new UserDataContainer();
FinalData.SetFields(CombinedDatas);
FinalData.Save(FinalDataPath);
로드 두 파일 : 당신은 당신이 할 수있는 병합 할 때 나중에
객체를 프로그래밍 할 때 두 객체의'Data' 필드를 결합하여 객체를 xml로 저장하십시오. 다행히 그것이 당신을 시작하게 할 것이고, 그 3 단계 각각을 개별적으로 해결하는 방법에 초점을 맞추면 문제를 쉽게 연구 할 수있을 것입니다. –