C # study notes 8 (Serialization, ActiveX Control)

zhaozj2021-02-16  66

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 binaryformatter = new binaryformatter (); Products P = (Pro DuCTS) 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;

转载请注明原文地址:https://www.9cbs.com/read-24448.html

New Post(0)