发布网友 发布时间:2022-04-24 14:21
共1个回答
热心网友 时间:2022-04-13 13:30
public
class
cat
{
public
string
color
{
get;
set;
}
public
int
speed
{
get;
set;
}
public
string
name{
get;
set;
}
}
//序列化
var
cat1=new
cat{color="write",speed=50,name="mimi"
};
xmlserializer
ser
=
new
xmlserializer(typeof(cat));
memorystream
ms
=
new
memorystream();
ser.serialize(ms,
cat1);
string
xmlstring
=
encoding.utf8.getstring(ms.toarray());
//xmlstring要保存数据库字符串
//反序列化
xmlserializer
dser
=
new
xmlserializer(typeof(cat));
//xmlstring数据库获取字符串
stream
xmlstream
=
new
memorystream(encoding.utf8.getbytes(xmlstring));
cat
cat2=dser.deserialize(xmlstream)
as
cat;//cat2
要class象
a