首页 > 开发 > 综合 > 正文

C#学习笔记之八(Serialization, ActiveX Control)

2024-07-21 02:19:43
字体:
来源:转载
供稿:网友
serialization:
1. use attribute
// "[serializable]"
2. formatter
// "binaryformatter binaryformatter = new binaryformatter();"
3.[noserialized]

//example
// if the data can generate based some data, then no need to serialize them.
// overload the onserialization() method to do the caculate work
[serializable]
class products : ideserializationcallback
{
private long statnumber = 1;
private long endnumber;
[nonserialized] private long[] theproducts;
...
public static void main()
{
products p = new products(1, 10);
p.serialize();
products p2 = products.deserialize();
p2.displayproducts();
}
public void serialize()
{
filestream filestream =
new filestream("doproducts1.out", filemode.create);
binaryformatter.serialize(filestream, this);
filestream.close();
}
public static products deserialize()
{
filestream filestream =
new filestream("doproduct1.out", filemode.open);
binaryformatter binaryformattter =
new binaryformatter();
products p = (products) binaryformatter.deserialize(filestream);
filestream.close();
return p;
}

pubic virtual void ondeserialization(object sender)
{
//caculate the none serialized data based on the serialized data
}

}

activex control:
1. write in vb or vc
2. register activex control in dos command windows
regsvr32 a.ocx
3. add control to c# project
// tool->customize toolbox->com components->select your component
4. call
// label1.text = axcalculator.add(ref left, ref right).tostring;

最大的网站源码资源下载站,

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表