一個可序列化的類別示範

旧时模样 提交于 2019-11-26 21:47:21

XML 序列化 (Serialization) 是將物件公用屬性和欄位轉換為儲存或傳輸所用的序列格式 (此處即為 XML) 的程序。 

None.gifusing System;
None.gif
using System.Xml.Serialization;
None.gif
None.gif
namespace CarService
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// car 的摘要描述。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    [XmlInclude(typeof(Car))]
InBlock.gif    public class Car
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public string petName;
InBlock.gif        
public int maxSpeed;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public Car() dot.gif{}
InBlock.gif
InBlock.gif        
public Car(string petName, int speed)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.petName = petName;
InBlock.gif            
this.maxSpeed = speed;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/jason820/archive/2004/11/09/61835.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!