C# 序列化与反序列化之xml对属性或者字段的子类化的子对象进行序列化的解决方案

xml序列化涉及到XmlRoot,XmlInclude,XmlElement,XmlAttribute,XmlType(用于继承的子类),XmlArray,XmlArrayItem(集合和集合项)等

新建控制台console项目,添加类XmlPerson以及XmlPerson的子类XmlStudent,XmlTeacher,添加Address类以及Address的的子类USAddress,AUAddress

1、运行的主方法代码如下:

using log4net;
using System;
using System.Data;
using System.Data.SQLite;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.IO.MemoryMappedFiles;
using System.IO.Pipes;
using System.Linq;
using System.Net;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Runtime.Serialization; namespace SupremeConsole
{
class Program
{ static void Main(string[] args)
{ TestSeri();
Console.ReadLine();
} public static void TestSeri()
{
//Team team = new Team { TName="123",PlayerList = { new Person { Name="1",Age=1},new Person { Name = "2", Age = 2 } } };
#region BinarySerialize 必须添可序列化属性,即要序列化的对象必须添加SerializableAttribute属性,[Serializable]
//string s = SerializeManager.Instance.BinarySerialize<Team>(team);//序列化
//Console.ForegroundColor = ConsoleColor.Green;
//Console.WriteLine("测试序列化成功。。。");
//Console.WriteLine($"测试序列化结果:\r\n{s}"); //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "序列化11111.bin");//序列化
//SerializeManager.Instance.BinarySerialize<Team>(team, path); //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "序列化11111.bin");
//Team test = SerializeManager.Instance.BinaryDeserialize<Team>(path);//反序列化
//if (test != null)
//{
// Console.WriteLine($"测试序列化结果:{test.ToString()}");
//}
#endregion #region SoapSerialize 必须添可序列化属性,即要序列化的对象必须添加SerializableAttribute属性,[Serializable]
//string s = SerializeManager.Instance.SoapSerialize<Team>(team);//序列化
//Console.ForegroundColor = ConsoleColor.Green;
//Console.WriteLine("测试序列化成功。。。");
//Console.WriteLine($"测试序列化结果:\r\n{s}"); //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Soap序列化.xml");//序列化
//SerializeManager.Instance.SoapSerialize<Team>(team, path); //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Soap序列化.xml");
//Team test = SerializeManager.Instance.SoapDeserialize<Team>(path);//反序列化
//if (test != null)
//{
// Console.WriteLine($"测试序列化结果:{test.ToString()}");
//}
#endregion #region XmlSerialize 要序列化的对象可以不添加SerializableAttribute属性,[Serializable]
//XmlPerson xmlPerson = new XmlPerson { Name = "1111", Age = 12,Address="住址。。。。" };
XmlPerson xmlPerson = new XmlPerson { Name = "", Age = , HomeAddress = new Address { Street = "默默大街三号", PostCode = "" } };
//XmlPerson xmlPerson = new XmlPerson { Name = "1111", Age = 12, HomeAddress = new USAddress { Street = "默默大街三号", PostCode = "233664", Neighbor="邻居666" } };
string s = SerializeManager.Instance.XmlSerialize<XmlPerson>(xmlPerson);//序列化
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("测试序列化成功。。。");
Console.WriteLine($"测试序列化结果:\r\n{s}"); //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "序列化.txt");//序列化
//SerializeManager.Instance.XmlSerialize<TestClass>(testClass, path); //备用
//string json = "{\"Address\":\"中国南京\",\"Age\":10,\"Id\":1,\"Name\":\"张三\",\"Sex\":\"男\"}";
//TestClass test = SerializeManager.Instance.DataContractJsonDeserializeJson<TestClass>(json);//反序列化
//if (test != null)
//{
// Console.WriteLine($"测试序列化结果:{test.ToString()}");
//} //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "序列化.txt");
//TestClass test = SerializeManager.Instance.XmlDeserialize<TestClass>(path);//反序列化
//if (test != null)
//{
// Console.WriteLine($"测试序列化结果:{test.ToString()}");
//}
#endregion
}
}
}

2、xml对属性或者字段的子类化的子对象进行序列化,首先添加类XmlPerson以及XmlPerson的子类XmlStudent,XmlTeacher,添加Address类以及Address的的子类USAddress,AUAddress

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization; namespace SupremeConsole
{
#region 继承XmlPerson以及继承的子类
/// <summary>
/// xml序列化测试类
/// </summary>
//继承XmlPerson的子类XmlStudent,XmlTeacher的序列化
//[XmlInclude(typeof(继承的子类1))]//XmlInclude指明了,继承子类的序列化的类型,如 XmlInclude(typeof(XmlStudent)),或者再序列化的时候添加子类类型XmlSerializer xs = new XmlSerializer (typeof (XmlPerson),new Type[] { typeof (继承的子类1), typeof (继承的子类2)} );,如:new Type[] { typeof (XmlStudent), typeof (XmlTeacher)};
[XmlRoot("haha")]
//[XmlInclude(typeof(XmlStudent))]
//[XmlInclude(typeof(XmlTeacher))]
public class XmlPerson
{
/// <summary>
/// 姓名
/// </summary>
[XmlElement("MyName", Order = )]
public string Name { get; set; } /// <summary>
/// 年龄
/// </summary>
[XmlAttribute("MyAge")]
public int Age { get; set; } ///// <summary>
///// 住址
///// </summary>
//[XmlElement("Residence", Order = 1)]
//public string Address { get; set; } /// <summary>
/// 住址
/// </summary>
[XmlElement("Residence", Order = )]
public Address HomeAddress = new Address();//常规序列化
} [XmlType("SubXmlPersonIsXmlStudent")]//XmlStudent序列化后的名称
public class XmlStudent : XmlPerson
{
/// <summary>
/// 学号
/// </summary>
public string StuNumber { get; set; }
} [XmlType("SubXmlPersonIsXmlTeacher")]//XmlTeacher序列化后的名称
public class XmlTeacher : XmlPerson
{
/// <summary>
/// 工号
/// </summary>
public string TeachNumber { get; set; } }
#endregion #region Address以及继承的子类 public class Address //常规序列化
{
public string Street, PostCode;
} [XmlType("USAddressISSubAddress")]
public class USAddress : Address //子类的序列化
{
public string Neighbor; //邻居
} [XmlType("AUAddressISSubAddress")]
public class AUAddress : Address //子类的序列化
{
public string OldNeighbor; //邻居
}
#endregion
}

运行效果:

测试序列化成功。。。
测试序列化结果:
<?xml version="1.0"?>
<haha xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" MyAge="12">
<Residence>
<Street>默默大街三号</Street>
<PostCode>233664</PostCode>
</Residence>
<MyName>1111</MyName>
</haha>

运行结果中的红色标记就是XmlPerson中的HomeAddress 设置的别名Residence

/// <summary>
/// 住址
/// </summary>
[XmlElement("Residence", Order = 1)]
public Address HomeAddress = new Address();//常规序列化

修改XmlPerson中的

[XmlElement("Residence", Order = 1)]
public Address HomeAddress = new Address();//常规序列化

改成

[XmlElement("Residence", Order = 1)]
public Address HomeAddress = new USAddress();//子类的序列化

同时修改 Address,在Address类上添加特性[XmlInclude(typeof(USAddress))],[XmlInclude(typeof(AUAddress))]

[XmlInclude(typeof(USAddress))]
[XmlInclude(typeof(AUAddress))]
public class Address //常规序列化
{
public string Street, PostCode;
}

把TestSeri法中的

XmlPerson xmlPerson = new XmlPerson { Name = "1111", Age = 12, HomeAddress = new Address { Street = "默默大街三号", PostCode = "233664" } };

改成

XmlPerson xmlPerson = new XmlPerson { Name = "1111", Age = 12, HomeAddress = new USAddress { Street = "默默大街三号", PostCode = "233664", Neighbor="邻居666" } };

运行结果:

测试序列化成功。。。
测试序列化结果:
<?xml version="1.0"?>
<haha xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" MyAge="12">
<Residence xsi:type="USAddressISSubAddress">
<Street>默默大街三号</Street>
<PostCode>233664</PostCode>
<Neighbor>邻居666</Neighbor>
</Residence>
<MyName>1111</MyName>
</haha>

 

运行的结果来看出现了 Residence xsi:type="USAddressISSubAddress",出现的原因是在Address类上添加特性[XmlInclude(typeof(USAddress))],这就是xml对属性或者字段的子类化的子对象进行序列化的结果

要想出现下面的效果

修改

[XmlElement("Residence", Order = 1)]
//public Address HomeAddress = new USAddress();//子类的序列化

改为

[XmlElement("Residence", typeof(Address), Order = 1)]
[XmlElement("USAddressISSubAddressResidence", typeof(USAddress), Order = 1)]
[XmlElement("AUAddressISSubAddressResidence", typeof(AUAddress), Order = 1)]
public Address HomeAddress = new USAddress();//子类的序列化

这时候就可以达到上述效果,但是Address类上添加特性[XmlInclude(typeof(USAddress))]对结果没有影响,可以去掉。

3、xml对属性或者字段是泛型集合的序列化处理方式如下

首先把XmlPerson类中的

public Address HomeAddress = new USAddress();//子类的序列化

改成

[XmlArray("集合列表的名称", Order = 1)]//默认序列化以后的名称是Addresses ,现在通过XmlArray来修改为指定的名称,如:[XmlArray("集合列表的名称", Order = 1)]
[XmlArrayItem("集合列表中的项的名称")]//默认序列化以后的名称是Address,现在通过XmlArrayItem来修改为指定的名称,如:[XmlArrayItem("集合列表中的项的名称")]
public List<Address> Addresses = new List<Address>();

注意:XmlElement、XmlText 和 XmlAnyElement 不能与 XmlAttribute、XmlAnyAttribute、XmlArray 或 XmlArrayItem 一起使用,否则会报错。

把TestSeri方法中的

XmlPerson xmlPerson = new XmlPerson { Name = "1111", Age = 12, HomeAddress = new USAddress { Street = "默默大街三号", PostCode = "233664", Neighbor="邻居666" } };

改成

XmlPerson xmlPerson = new XmlPerson { Name = "1111", Age = 12, Addresses = new List<Address> { new Address { Street = "大街三三号", PostCode = "123"}, new USAddress { Street = "大街六六号", PostCode = "456", Neighbor = "邻居666" } } };

运行效果

把   public List<Address> Addresses = new List<Address>();上的特性改成

[XmlElement("Address", typeof(Address), Order = 1)]
[XmlElement("AUAddress", typeof(AUAddress))]
[XmlElement("USAddress", typeof(USAddress))]
public List<Address> Addresses = new List<Address>();

把TestSeri方法中的

XmlPerson xmlPerson = new XmlPerson { Name = "1111", Age = 12, Addresses = new List<Address> { new Address { Street = "大街三三号", PostCode = "123"}, new USAddress { Street = "大街六六号", PostCode = "456", Neighbor = "邻居666" } } };

改成

XmlPerson xmlPerson = new XmlPerson { Name = "1111", Age = 12, Addresses = new List<Address> { new Address { Street = "大街三三号", PostCode = "123"}, new USAddress { Street = "大街六六号", PostCode = "456", Neighbor = "邻居666" }, new AUAddress { Street = "大街八八号", PostCode = "789", OldNeighbor = "旧朋友邻居8888" } } };

运行效果

[XmlElement("Address", typeof(Address), Order = 1)]
[XmlElement("AUAddress", typeof(AUAddress))]
[XmlElement("USAddress", typeof(USAddress))]
public List<Address> Addresses = new List<Address>();

上的特性

改成

[XmlArray(Order = 1)]
[XmlArrayItem("Address", typeof(Address))]
[XmlArrayItem("AUAddress", typeof(AUAddress))]
[XmlArrayItem("USAddress", typeof(USAddress))]
public List<Address> Addresses = new List<Address>();

运行效果

上述测试的全部代码如下:

Main主方法代码:

using log4net;
using System;
using System.Data;
using System.Data.SQLite;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.IO.MemoryMappedFiles;
using System.IO.Pipes;
using System.Linq;
using System.Net;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Runtime.Serialization;
using System.Collections.Generic; namespace SupremeConsole
{
class Program
{
static void Main(string[] args)
{
TestSeri();
Console.ReadLine();
} public static void TestSeri()
{
//Team team = new Team { TName="123",PlayerList = { new Person { Name="1",Age=1},new Person { Name = "2", Age = 2 } } };
#region BinarySerialize 必须添可序列化属性,即要序列化的对象必须添加SerializableAttribute属性,[Serializable]
//string s = SerializeManager.Instance.BinarySerialize<Team>(team);//序列化
//Console.ForegroundColor = ConsoleColor.Green;
//Console.WriteLine("测试序列化成功。。。");
//Console.WriteLine($"测试序列化结果:\r\n{s}"); //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "序列化11111.bin");//序列化
//SerializeManager.Instance.BinarySerialize<Team>(team, path); //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "序列化11111.bin");
//Team test = SerializeManager.Instance.BinaryDeserialize<Team>(path);//反序列化
//if (test != null)
//{
// Console.WriteLine($"测试序列化结果:{test.ToString()}");
//}
#endregion #region SoapSerialize 必须添可序列化属性,即要序列化的对象必须添加SerializableAttribute属性,[Serializable]
//string s = SerializeManager.Instance.SoapSerialize<Team>(team);//序列化
//Console.ForegroundColor = ConsoleColor.Green;
//Console.WriteLine("测试序列化成功。。。");
//Console.WriteLine($"测试序列化结果:\r\n{s}"); //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Soap序列化.xml");//序列化
//SerializeManager.Instance.SoapSerialize<Team>(team, path); //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Soap序列化.xml");
//Team test = SerializeManager.Instance.SoapDeserialize<Team>(path);//反序列化
//if (test != null)
//{
// Console.WriteLine($"测试序列化结果:{test.ToString()}");
//}
#endregion #region XmlSerialize 要序列化的对象可以不添加SerializableAttribute属性,[Serializable]
//XmlPerson xmlPerson = new XmlPerson { Name = "1111", Age = 12,Address="住址。。。。" };
//XmlPerson xmlPerson = new XmlPerson { Name = "1111", Age = 12, HomeAddress = new Address { Street = "默默大街三号", PostCode = "233664" } };
//XmlPerson xmlPerson = new XmlPerson { Name = "1111", Age = 12, HomeAddress = new USAddress { Street = "默默大街三号", PostCode = "233664", Neighbor="邻居666" } };
XmlPerson xmlPerson = new XmlPerson { Name = "", Age = , Addresses = new List<Address> { new Address { Street = "大街三三号", PostCode = ""}, new USAddress { Street = "大街六六号", PostCode = "", Neighbor = "邻居666" }, new AUAddress { Street = "大街八八号", PostCode = "", OldNeighbor = "旧朋友邻居8888" } } };
string s = SerializeManager.Instance.XmlSerialize<XmlPerson>(xmlPerson);//序列化
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("测试序列化成功。。。");
Console.WriteLine($"测试序列化结果:\r\n{s}"); //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Addresses序列化.txt");//序列化
//SerializeManager.Instance.XmlSerialize<XmlPerson>(xmlPerson, path); //string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Addresses序列化.txt");
//XmlPerson test = SerializeManager.Instance.XmlDeserialize<XmlPerson>(path);//反序列化
//if (test != null)
//{
// Console.WriteLine($"测试序列化结果:{test.ToString()}");
//}
#endregion
}
}
}

xmlPerson类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization; namespace SupremeConsole
{
#region 继承XmlPerson以及继承的子类
/// <summary>
/// xml序列化测试类
/// </summary>
//继承XmlPerson的子类XmlStudent,XmlTeacher的序列化
//[XmlInclude(typeof(继承的子类1))]//XmlInclude指明了,继承子类的序列化的类型,如 XmlInclude(typeof(XmlStudent)),或者再序列化的时候添加子类类型XmlSerializer xs = new XmlSerializer (typeof (XmlPerson),new Type[] { typeof (继承的子类1), typeof (继承的子类2)} );,如:new Type[] { typeof (XmlStudent), typeof (XmlTeacher)};
[XmlRoot("haha")]
//[XmlInclude(typeof(XmlStudent))]
//[XmlInclude(typeof(XmlTeacher))]
public class XmlPerson
{
/// <summary>
/// 姓名
/// </summary>
[XmlElement("MyName", Order = )]
public string Name { get; set; } /// <summary>
/// 年龄
/// </summary>
[XmlAttribute("MyAge")]
public int Age { get; set; } ///// <summary>
///// 住址
///// </summary>
//[XmlElement("Residence", Order = 1)]
//public string Address { get; set; } ///// <summary>
///// 住址
///// </summary>
//[XmlElement("Residence", Order = 1)]
//public Address HomeAddress = new Address();//常规序列化 ///// <summary>
///// 住址
///// </summary>
//[XmlElement("Residence", Order = 1)]
//public Address HomeAddress = new USAddress();//子类的序列化 ///// <summary>
///// 住址
///// </summary>
//[XmlElement("Residence", typeof(Address), Order = 1)]
//[XmlElement("USAddressISSubAddressResidence", typeof(USAddress), Order = 1)]
//[XmlElement("AUAddressISSubAddressResidence", typeof(AUAddress), Order = 1)]
//public Address HomeAddress = new USAddress();//子类的序列化 ///// <summary>
///// 地址集合
///// </summary>
//[XmlArray("集合列表的名称", Order = 1)]
//[XmlArrayItem("集合列表中的项的名称")]
//public List<Address> Addresses = new List<Address>();
[XmlArray(Order = )]
[XmlArrayItem("Address", typeof(Address))]
[XmlArrayItem("AUAddress", typeof(AUAddress))]
[XmlArrayItem("USAddress", typeof(USAddress))]
public List<Address> Addresses = new List<Address>(); //[XmlElement("Address", typeof(Address), Order = 1)]
//[XmlElement("AUAddress", typeof(AUAddress))]
//[XmlElement("USAddress", typeof(USAddress))]
//public List<Address> Addresses = new List<Address>();
} [XmlType("SubXmlPersonIsXmlStudent")]//XmlStudent序列化后的名称
public class XmlStudent : XmlPerson
{
/// <summary>
/// 学号
/// </summary>
public string StuNumber { get; set; }
} [XmlType("SubXmlPersonIsXmlTeacher")]//XmlTeacher序列化后的名称
public class XmlTeacher : XmlPerson
{
/// <summary>
/// 工号
/// </summary>
public string TeachNumber { get; set; } }
#endregion #region Address以及继承的子类 [XmlInclude(typeof(USAddress))]
[XmlInclude(typeof(AUAddress))]
public class Address //常规序列化
{
public string Street, PostCode;
} [XmlType("USAddressISSubAddress")]
public class USAddress : Address //子类的序列化
{
public string Neighbor; //邻居
} [XmlType("AUAddressISSubAddress")]
public class AUAddress : Address //子类的序列化
{
public string OldNeighbor; //邻居
}
#endregion
}

C# 序列化与反序列化之xml对属性或者字段的子类化的子对象进行序列化的解决方案的更多相关文章

  1. JSON 序列化与反序列化, 与XML相互转换.

    方式一: 使用于 JavaScriptSerializer类 适用于普通场景, Excel导入导出, 前台传输查询参数直接处理等. JavaScriptSerializer serializer = ...

  2. C# XML序列化与反序列化与XML格式详解

    1.https://www.cnblogs.com/sandyliu1999/p/4844664.html XML是有层次结构的,序列化实际就是内存化,用连续的结构化的内存来存储表示一个对象,那么这两 ...

  3. C#学习日志 day8 -------------- async await 异步方法入门(引用博客)以及序列化和反序列化的XML及json实现

    首先是异步方法的介绍,这里引用自http://www.cnblogs.com/LoveJenny/archive/2011/11/01/2230933.html async and await 简单的 ...

  4. C# 序列化与反序列化之xml通过实现IXmlSerializable进行序列化的解决方案

    新建控制台console项目,添加XmlPersonIXmlSerializable类,和AddressIXmlSerializable类(实现IXmlSerializable)以及AddressIX ...

  5. go语言学习 ---struct 对象的序列化和反序列化(xml)

    实例1: //main package main import ( "encoding/xml" "fmt" ) type person struct { Na ...

  6. 将对象序列化,反序列化到XML

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  7. .NET中XML序列化和反序列化常用类和用来控制XML序列化的属性总结(XmlSerializer,XmlTypeAttribute,XmlElementAttribute,XmlAttributeAttribute,XmlArrayAttribute...)

    序列化和反序列化是指什么? 序列化(seriallization): 将对象转化为便于传输的数据格式, 常见的序列化格式:二进制格式,字节数组,json字符串,xml字符串.反序列化(deserial ...

  8. C#: .net序列化及反序列化 [XmlElement(“节点名称”)] [XmlAttribute(“节点属性”)] (下篇)

    介绍 XML 序列化 .NET Framework 开发员指南   序列化是将对象转换为容易传输的格式的过程.例如,可以序列化一个对象,然后使用 HTTP 通过 Internet 在客户端和服务器之间 ...

  9. PHP中的抽象类与抽象方法/静态属性和静态方法/PHP中的单利模式(单态模式)/串行化与反串行化(序列化与反序列化)/约束类型/魔术方法小结

      前  言  OOP  学习了好久的PHP,今天来总结一下PHP中的抽象类与抽象方法/静态属性和静态方法/PHP中的单利模式(单态模式)/串行化与反串行化(序列化与反序列化). 1  PHP中的抽象 ...

随机推荐

  1. 在Node.js中使用ejsexcel输出EXCEL文件

    1.背景 在Nodejs应用程序中输出Excel,第一印象想到的一般是node-xlsx,这类插件不仅需要我们通过JS写入数据,还需要通过JS进行EXCEL显示样式的管理. 这是个大问题,不仅代码冗余 ...

  2. 05-Vue组件

    定义Vue组件 什么是组件: 组件的出现,就是为了拆分Vue实例的代码量的,能够让我们以不同的组件,来划分不同的功能模块,将来我们需要什么样的功能,就可以去调用对应的组件即可: 组件化和模块化的不同: ...

  3. caffe库源码剖析——net层

    net层的功能实现主要涉及到net.hpp和net.cpp文件,让我们要捋顺它是干了什么,是如何实现的. 1. net层使用到的参数 第一步要做的事,就是查看caffe.proto文件,弄清楚net都 ...

  4. 解锁 redis 锁的正确姿势

    redis 是 php 的好朋友,在 php 写业务过程中,有时候会使用到锁的概念,同时只能有一个人可以操作某个行为.这个时候我们就要用到锁.锁的方式有好几种,php 不能在内存中用锁,不能使用 zo ...

  5. List加载因子和扩容因子

    List.Map.set的加载因子,默认初始容量和扩容增量 首先,这三个概念说下.初始大小,就是创建时可容纳的默认元素个数:加载因子,表示某个阀值,用0~1之间的小数来表示,当已有元素占比达到这个阀值 ...

  6. rootkit——一种特殊的恶意软件,它的功能是在安装目标上隐藏自身及指定的文件、进程和网络链接等信息,一般都和木马、后门等其他恶意程序结合使用

    Rootkit是指其主要功能为隐藏其他程式进程的软件,可能是一个或一个以上的软件组合:广义而言,Rootkit也可视为一项技术.   目录 1 rootkit是什么 2 rootkit的功能 root ...

  7. php中的设计模式---工厂模式及单例模式

    这两个练习放在一起处理. 在python中,这些模式都有的. 要记得三大类模式:创建型,结构型,行为型. NotFoundException.php <?php namespace Bookst ...

  8. vue 项目中安装npm--save-dev 和 --save 命令

    在vue项目中我们常用npm install 安装模块或插件 有两种命令把他们写入到 package.json 文件里面去 例如安装axios 安装到开发环境npm axios --save-dev ...

  9. opencv想到的

    opencv是用C++写的库,包了多种语言接口,包括C,C++,python,java等. OpenCV 是一个开放源代码的计算机视觉库,目前在科研和开发中被广泛使用.OpenCV 由一系列 C 函数 ...

  10. CodeForces - 348D:Turtles(LGV定理)

    题意:给定N*M的矩阵,'*'表示可以通过,'#'表示不能通过,现在要找两条路径从[1,1]到[N,M]去,使得除了起点终点,没有交点. 思路:没有思路,就是裸题.  Lindström–Gessel ...