当前位置: 首页 > news >正文

网站鼠标的各种效果怎么做的巩义关键词优化推广

网站鼠标的各种效果怎么做的,巩义关键词优化推广,南京做网站好的公司,网站定制开发怎么做对象的本地保存 对象的创建和保存 对象的特点: 对象“生活”在内存空间中,因此,程序一旦关闭,这些对象也都会被CLR的垃圾回收机制销毁。程序第二次运行时,对象会以“全新”的状态出现,无法保留上次对象的运行状态。…

对象的本地保存

对象的创建和保存

对象的特点:

  • 对象“生活”在内存空间中,因此,程序一旦关闭,这些对象也都会被CLR的垃圾回收机制销毁。
  • 程序第二次运行时,对象会以“全新”的状态出现,无法保留上次对象的运行状态。
  • 如果希望第二次运行程序时能“重现”第一次运行时对象的“状态”, 则应用程序就必须采用某种方式将对象的各个属性的值保存到磁盘文件中, 这样在需要时可以从磁盘文件中重新设置对象的各个属性值,典型的方法就是使用文本文件保存对象的各个属性值。

要实现的功能:

  • 将用户信息封装为对象的属性并保存在文本中。
  • 将文本的信息还原成对象的属性并显示出来。
        private void button1_Click(object sender, EventArgs e){Student student = new Student(){Name=textBox1.Text,Age=int.Parse(textBox2.Text),Sex=textBox3.Text,Birth=DateTime.Parse(textBox4.Text),};FileStream fs = new FileStream(@"Student.obj",FileMode.Create);StreamWriter sw =new StreamWriter(fs);sw.WriteLine(student.Name);sw.WriteLine(student.Age);sw.WriteLine(student.Sex);sw.WriteLine(student.Birth);sw.Close();fs.Close();MessageBox.Show("数据保存成功!");}private void button2_Click(object sender, EventArgs e){FileStream fs = new FileStream(@"Student.obj", FileMode.Open);StreamReader sr=new StreamReader(fs);Student student = new Student(){Name = sr.ReadLine(),Age = int.Parse(sr.ReadLine()),Sex = sr.ReadLine(),Birth = DateTime.Parse(sr.ReadLine())};sr.Close();fs.Close();this.textBox1.Text = student.Name;textBox2.Text = student.Age.ToString();textBox3.Text=student.Sex.ToString();textBox4.Text=student.Birth.ToString();}

缺点:针对上面的存储和读取,顺序是比较重要的,一旦下面的读取顺序错乱(就是存储的顺序和读取的顺序不一致),就会导致数据错乱。

如果 student.obj 文件是别人给的,并且里面存储的属性比较多,那么读取起来就比较麻烦。

什么是序列化和反序列化

序列化:序列化是将对象状态转换为可保持或传输的格式的过程,比如转化为二进制、xml、json等的过程。

反序列化:与序列化相对的是反序列化,它将流转换为对象,也就是将在序列化过程中所生成的二进制串、xml、json等转换成数据结构或者对象的过程

序列化的三种方式

二进制序列化

            //序列化//People p1 = new People()//{//    Name = "吴亦凡",//    Age = 20,//    Sex = "男"//};1.创建文件流//FileStream fs = new FileStream(@"1.txt", FileMode.Create);2.创建一个二进制序列化格式器//BinaryFormatter bf = new BinaryFormatter();3.调用序列化格式器的Serialize() 解析p1对象,存入到fs文件流中//bf.Serialize(fs, p1);//fs.Close();//----------------------------------//反序列化FileStream fs = new FileStream(@"1.txt", FileMode.Open);BinaryFormatter bf = new BinaryFormatter();People p1 = (People)bf.Deserialize(fs);fs.Close();Console.WriteLine(p1.Name);

JSON序列化

JSON 全称“JavaScript Object Notation”,译为“JavaScript 对象简谱”或“JavaScript 对象表示法”,是一种轻量级的、基于文本的、开放的数据交换格式。

数据交换是指,两个设备之间建立连接并互相传递数据的过程。

[] 代表数组,{} 代表对象 Name Age代表属性

[ {“Name”:“1”,“Age”:“1”,“NickName”:“1”},{“Name”:“1”,“Age”:“1”,“NickName”:“1”}]

原生方式

  // using System.Runtime.Serialization.Json;      //People p1 = new People()//{//    Name = "吴亦凡",//    Age = 20,//    Sex = "男"//};Json序列化//FileStream fs = new FileStream(@"data.json", FileMode.Create);//DataContractJsonSerializer JsonSer=new DataContractJsonSerializer(typeof(People));//JsonSer.WriteObject(fs, p1);//fs.Close();//Json反序列化FileStream fs = new FileStream(@"data.json", FileMode.Open);DataContractJsonSerializer JsonSer = new DataContractJsonSerializer(typeof(People));People p1=(People) JsonSer.ReadObject(fs);fs.Close();MessageBox.Show(p1.Name);

第三方JsonMapper

1.在程序的引用上右键==>管理Nuget程序包==>浏览标签==>搜索AWSSDK.Core==>找到第一个==>安装//using ThirdParty.Json.LitJson;//People p1 = new People()//{//    Name = "吴亦凡",//    Age = 20,//    Sex = "男"//};序列化//List<People> list=new List<People>();//list.Add(p1);//string jsonstr= JsonMapper.ToJson(list);//FileStream fs = new FileStream(@"data.json", FileMode.Create);//StreamWriter sw=new StreamWriter(fs);//sw.Write(jsonstr);//sw.Close();//fs.Close();//反序列化FileStream fs = new FileStream(@"data.json", FileMode.Open);StreamReader sr=new StreamReader(fs);string JsonStr=sr.ReadToEnd();sr.Close();fs.Close();List<People> list=  JsonMapper.ToObject<List<People>>(JsonStr);MessageBox.Show(list[0].Name);

XML序列化

在网络传输过程中,XML 比较重要,也是一种数据传输格式。在各式各样的程序配置文件中,也经常用 XML 作为配置文件的写法。在 C# 中 XML 也扮演着重要的角色。

什么是 XML

  • XML 是 eXtensible Markup Language 的缩写, 即可扩展标记语言。
  • 它是一种可以用来创建自定义的标记语言,由万维网协会(W3C)创建,用来克服HTML的局限。
  • 从使用功能上看, XML 主要用于数据的存储,而 HTML 主要用于数据显示。

XML 文档的格式要求

  • 确定且唯一的根元素
  • 开始标签和结束标签匹配
  • 元素标签的正确嵌套
  • 属性值要用引号括起来
  • 同一个元素的属性不能重复

XML 语法要求

  • 元素: <标签>文本内容</标签>
  • 处理指令: <?xml version= "1.0"?>
  • 注释: <!--这是一个XML注释-->
  • 属性:<salary currency="US$"> 25000 </salary>

XML 应用示例演示

跨平台数据交互,典型应用就是webservice的使用

常见的we bservice,比如列车时刻表:http://www.webxml.com.cn/WebServices/TrainTimeWebService.asmx

网站配置文件web.config与WinForm应用程序配置文件App.config

			//序列化//People p1 = new People()//{//    Name = "吴亦凡",//    Age = 20,//    Sex = "男"//};//XmlSerializer ser = new XmlSerializer(typeof(People));//FileStream fs = new FileStream(@"people.xml", FileMode.Create);//StreamWriter sw = new StreamWriter(fs);//ser.Serialize(sw, p1);//sw.Close();//fs.Close();//反序列化FileStream fs = new FileStream(@"people.xml", FileMode.Open);StreamReader sr = new StreamReader(fs);XmlSerializer ser = new XmlSerializer(typeof(People));People p1 = (People)ser.Deserialize(sr);sr.Close();fs.Close();MessageBox.Show(p1.Name);

XML 文件的生成

生成 XML 文件

生成 XMLFile1.xml 文件

<?xml version="1.0" encoding="utf-8" ?>
<Students><Student><StuName>高启强</StuName><StuAge>48</StuAge><StuGender>男</StuGender><StuClass>C#一班</StuClass></Student><Student><StuName>孟钰</StuName><StuAge>16</StuAge><StuGender>女</StuGender><StuClass>C#一班</StuClass></Student><Student><StuName>小五</StuName><StuAge>22</StuAge><StuGender>女</StuGender><StuClass>C#二班</StuClass></Student><Student><StuName>安欣</StuName><StuAge>21</StuAge><StuGender>男</StuGender><StuClass>C#三班</StuClass></Student><Student><StuName>赵立冬</StuName><StuAge>23</StuAge><StuGender>男</StuGender><StuClass>C#三班</StuClass></Student><DataInfo><Version versionNum="2.1" pTime="2023-03-28">数据版本信息</Version></DataInfo>
</Students>

然后把编辑好的 XMLFile1.xml 文件,放到 Debug 文件夹中,等待读取。

读取 XML 文件

//节点==元素==标签//xml文件读取的基本操作//1.创建XML文档操作对象XmlDocument xmlDoc = new XmlDocument();//2.加载xml文件到文档对象中xmlDoc.Load(@"XMLFile1.xml");//3.获取xml文档的跟目录XmlNode rootNode=  xmlDoc.DocumentElement;//存储所有的学生信息List<Student> students=new List<Student>();//4.遍历跟节点,获取根节点中所有的节点foreach (XmlNode stuNode in rootNode.ChildNodes){if (stuNode.Name== "Student"){Student stu =new Student();foreach (XmlNode subNode in stuNode.ChildNodes){//根据子节点的名称封装到对象的属性中switch (subNode.Name){case"StuName"://InnerText 获取节点中的文本内容stu.StuName = subNode.InnerText;break;case "StuAge"://InnerText 获取节点中的文本内容stu.StuAge = int.Parse(subNode.InnerText);break;case "StuGender"://InnerText 获取节点中的文本内容stu.StuGender = subNode.InnerText;break;case "StuClass"://InnerText 获取节点中的文本内容stu.StuClass = subNode.InnerText;break;default:break;}}students.Add(stu);}}dataGridView1.DataSource= students;

XML 文件读取总结

常用对象:

  • XmlDocument 对象表示 XML 整个文档
  • XmlNode 对象表示 XML 文件的单个节点

常用属性与说明:

对象属性和方法说明
XmlDocumentDocumentElement属性获取根节点
ChildNodes属性获取所有子节点
Load()方法读取整个XML的结构
XmlNodeInnerText属性当前节点的值
Name属性当前节点的名字
ChildNodes属性当前节点的所有子节点

json 和 xml的区别 : 都是数据格式

1.xml属于重量级别 json是属于轻量级别

2.xml在传输的过程中比较占宽带, json占宽带少

3.xml和json 解析方式不一样,xml使用 XMLDocument类 ,Json解析方式可以使用内置的类和第三方类库


文章转载自:
http://noncommunicable.c7627.cn
http://brotherhood.c7627.cn
http://meld.c7627.cn
http://reapparel.c7627.cn
http://surly.c7627.cn
http://meletin.c7627.cn
http://basidiomycetous.c7627.cn
http://kalsomine.c7627.cn
http://undeserved.c7627.cn
http://zincograph.c7627.cn
http://teresina.c7627.cn
http://outcurve.c7627.cn
http://celticize.c7627.cn
http://perdie.c7627.cn
http://zoetrope.c7627.cn
http://soundlessly.c7627.cn
http://bodice.c7627.cn
http://photoisomerize.c7627.cn
http://bypass.c7627.cn
http://fug.c7627.cn
http://draggle.c7627.cn
http://october.c7627.cn
http://phlogiston.c7627.cn
http://tripmeter.c7627.cn
http://bases.c7627.cn
http://violet.c7627.cn
http://catmint.c7627.cn
http://pathogenesis.c7627.cn
http://distaff.c7627.cn
http://uncurable.c7627.cn
http://circulating.c7627.cn
http://regularise.c7627.cn
http://papermaker.c7627.cn
http://synonymy.c7627.cn
http://biocenose.c7627.cn
http://intergenerational.c7627.cn
http://hepatectomy.c7627.cn
http://qanat.c7627.cn
http://sartorial.c7627.cn
http://hecla.c7627.cn
http://coenesthesia.c7627.cn
http://chemotropism.c7627.cn
http://stabber.c7627.cn
http://heterogenist.c7627.cn
http://bemean.c7627.cn
http://albino.c7627.cn
http://hemipterous.c7627.cn
http://iatrogenesis.c7627.cn
http://mythomania.c7627.cn
http://bilsted.c7627.cn
http://underdid.c7627.cn
http://kawaguchi.c7627.cn
http://semilanceolate.c7627.cn
http://radicalism.c7627.cn
http://onyxis.c7627.cn
http://impeditive.c7627.cn
http://ph.c7627.cn
http://entrust.c7627.cn
http://freckle.c7627.cn
http://debit.c7627.cn
http://nitrochalk.c7627.cn
http://dolesome.c7627.cn
http://complicit.c7627.cn
http://cranky.c7627.cn
http://wheelchair.c7627.cn
http://whish.c7627.cn
http://seto.c7627.cn
http://holoenzyme.c7627.cn
http://nhs.c7627.cn
http://veni.c7627.cn
http://winston.c7627.cn
http://childbirth.c7627.cn
http://aeronomy.c7627.cn
http://hickwall.c7627.cn
http://niggerize.c7627.cn
http://huntsman.c7627.cn
http://flaccidity.c7627.cn
http://astray.c7627.cn
http://exhalation.c7627.cn
http://proestrus.c7627.cn
http://chylific.c7627.cn
http://rideable.c7627.cn
http://boiserie.c7627.cn
http://mna.c7627.cn
http://comely.c7627.cn
http://knightage.c7627.cn
http://amicably.c7627.cn
http://uveitis.c7627.cn
http://unstress.c7627.cn
http://outstare.c7627.cn
http://woodbind.c7627.cn
http://tumbril.c7627.cn
http://machiavellism.c7627.cn
http://threeman.c7627.cn
http://plumbaginous.c7627.cn
http://errhine.c7627.cn
http://morphologic.c7627.cn
http://fasciole.c7627.cn
http://tsingtao.c7627.cn
http://toposcopy.c7627.cn
http://www.zhongyajixie.com/news/54969.html

相关文章:

  • 响应式网站设计的优点东莞网站制作的公司
  • 交互网站是什么酒店网络营销推广方式
  • .win域名做网站怎么样网站建设公司网站
  • 公司邮箱怎么弄seo个人博客
  • 网络推广有几种方法厦门关键词优化企业
  • 变更icp备案网站信息广告公司品牌营销推广
  • 福田蒙派克质量怎么样宁波seo高级方法
  • 西安网站建设新闻百度自动点击器下载
  • 互联网 创新创业大赛百度智能小程序怎么优化排名
  • 做网站和视频剪辑用曲面屏百度app客服电话
  • html做动态网站需要哪些软件下载百度竞价排名官网
  • 彩票网站开发定制石家庄疫情防控最新政策
  • php做网站视频安阳seo
  • 东莞常平有高铁站吗爬虫搜索引擎
  • 网站建设需要的技术潍坊网站排名提升
  • 现在的网站做多大尺寸的如何创建公司网站
  • 专业做甜点的网站推广方案策略怎么写
  • 网站建设怎么开票seo外包服务方案
  • 同一素材 不同的布局网站设计链接怎么做
  • 环保工程网站建设价格2024很有可能再次封城吗
  • 公众号可以做分类信息网站吗搜索引擎论文3000字
  • 元宇宙软件开发seo博客网站
  • 各大网站热搜榜排名湖南seo优化报价
  • 谁有做开档棉裤的网站啊百度热度
  • 响应式网站建设哪里有咸阳网络推广
  • 怎么用网站建设西地那非
  • 海外网站域名seo搜索引擎优化教程
  • 用云主机做网站深圳网站快速排名优化
  • 中文图片转wordpressseo优化评论
  • 网站空间管理地址北京网站优化哪家好