程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C#學習筆記之八(Serialization, ActiveX Control)

C#學習筆記之八(Serialization, ActiveX Control)

編輯:關於C語言
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;
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved