国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

C#學(xué)習(xí)實例-將比較復(fù)雜的結(jié)構(gòu)序列化到文件中

2024-07-21 02:17:37
字體:
供稿:網(wǎng)友
 

/*
 filename:  savearrary2file.cs
 author : zhanghua
 date : 2005-8-27
 funciton: 本實例介紹如何將數(shù)組序列化到文件中, 
*/

using system;
using system.io;
using system.runtime.serialization;
using system.runtime.serialization.formatters.binary;

class class1
{
 ///<summary>
 ///應(yīng)用程序的主入口點
 ///</summary>
 [stathread]
 static void main(string[] args)
 {
  //
  //定義purchaseorder類型的數(shù)組對象obj, 設(shè)置其數(shù)組長度為2,
  //    并在其中保存了用戶要序列化的數(shù)據(jù)。
  purchaseorder obj = new purchaseorder();
  obj.itemsorders = new item[2];
  obj.itemsorders[0] = new item();
  obj.itemsorders[0].itemid = "first";
  obj.itemsorders[0].itemprice = 500.25m;
  
  obj.itemsorders[1] = new item();
  obj.itemsorders[1].itemid = "second";
  obj.itemsorders[0].itemprice = 66.88m;
  
  //創(chuàng)建一個文件流對象stream,指向文件myfile.bin
  iformatter formatter = new binaryformatter();
  stream stream = new filestream("d://myfile.bin", filemode.create,
  fileaccess.write, fileshare.none);
  
  //通過formatter對象以二進(jìn)制格式將obj對象序列化后到文件myfile.bin中
  formatter.serialize(stream,obj);
  stream.close();
 }
 
 //定義兩個可序列化的類purchaseorder 和item
 [serializable]
 public class purchaseorder
 {
  public item [] itemsorders;
 }
 
 
 [serializable]
 public class item
 {
  public string itemid;
  public decimal itemprice;
  
 }
 }

/*
 summary :  通過本實例可以學(xué)習(xí)到如何將比較復(fù)雜的結(jié)構(gòu)序列化到文件中
*/

  • 本文來源于網(wǎng)頁設(shè)計愛好者web開發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪問。
  • 發(fā)表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發(fā)表
    主站蜘蛛池模板: 普陀区| 洛南县| 安国市| 常熟市| 开封市| 伊宁县| 延津县| 宽城| 阳朔县| 天镇县| 固安县| 新宁县| 桃江县| 荔波县| 贡觉县| 清水县| 古交市| 克山县| 淳安县| 沙洋县| 瑞丽市| 井冈山市| 特克斯县| 巴东县| 诸城市| 奎屯市| 衡阳市| 青河县| 荆州市| 武隆县| 屏东市| 宜川县| 九江市| 常州市| 台北县| 聂荣县| 平阴县| 秦皇岛市| 浮山县| 开平市| 万盛区|