写在前面

.NET 5.0已经发布,C# 9.0也为我们带来了许多新特性,其中最让我印象深刻的就是init和record type,很多文章已经把这两个新特性讨论的差不多了,本文不再详细讨论,而是通过使用角度来思考这两个特性。

init

init是C# 9.0中引入的新的访问器,它允许被修饰的属性在对象初始化的时候被赋值,其他场景作为只读属性的存在。直接使用的话,可能感受不到init的意义,所以我们先看看之前是如何设置属性为只读的。

private set设置属性为只读

设置只读属性有很多种方式,本文基于private set来讨论。
首先声明一个产品类,如下代码所示,我们把Id设置成了只读,这个时候也就只能通过构造函数来赋值了。在通常情况下,实体的唯一标识是不可更改的,同时也要防止Id被意外更改。

  1. 1: public class Product
  1. 2: {
  1. 3: public Product(int id)
  1. 4: {
  1. 5: this.Id = id;
  1. 6: }
  1. 7:  
  1. 8: public int Id { get; private set; }
  1. 9: //public int Id { get; }
  1. 10:  
  1. 11: public string ProductName { get; set; }
  1. 12:  
  1. 13: public string Description { get; set; }
  1. 14: }
  1. 15:  
  1. 16: class Program
  1. 17: {
  1. 18: static void Main(string[] args)
  1. 19: {
  1. 20: Product product = new Product(1)
  1. 21: {
  1. 22: ProductName = "test001",
  1. 23: Description = "Just a description"
  1. 24: };
  1. 25:  
  1. 26: Console.WriteLine($"Current Product Id: {product.Id},\n\rProduct Name: {product.ProductName}, \n\rProduct Description: {product.Description}");
  1. 27:
  1. 28: //运行结果
  1. 29: //Current Product Id: 1,
  1. 30: //Product Name: test001,
  1. 31: //Product Description: Just a description
  1. 32:
  1. 33: Console.ReadKey();
  1. 34: }
  1. 35: }

.csharpcode, .csharpcode pre { font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }

record方式设置只读

使用init方式,是非常简单的,只需要把private set改成init就行了:

  1. 1: public int Id { get; init; }

.csharpcode, .csharpcode pre { font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }

两者比较

为了方便比较,我们可以将ProductName设置成了private set,然后通过ILSpy来查看一下编译后的代码,看看编译后的Id和ProductName有何不同

咋一看,貌似没啥区别,都使用到了initonly来修饰。但是如果仅仅只是替换声明方式,那么这个新特性似乎就没有什么意义了。
接下来我们看第二张图:

如图标记的那样,区别还是很明显的,通过init修饰的属性并没有完全替换掉set,由此看来微软在设计init的时候,还是挺用心思的,也为后面的赋值留下了入口。

  1. 1: instance void modreq([System.Runtime]System.Runtime.CompilerServices.IsExternalInit) set_Id (
  1. 2: int32 'value'
  1. 3: )

{ font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }另外在赋值的时候,使用private set修饰的属性,需要定义构造函数,通过构造函数赋值。而使用了init修饰的属性,则不需要定义构造函数,直接在对象初始化器中赋值即可。

  1. 1: Product product = new Product
  1. 2: {
  1. 3: Id = 1,
  1. 4: ProductName = "test001",
  1. 5: Description = "Just a description"
  1. 6: };
  1. 7:  
  1. 8: product.Id = 2;//Error CS8852 Init-only property or indexer 'Product.Id' can only be assigned in an object initializer, or on 'this' or 'base' in an instance constructor or an 'init' accessor.

{ font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }

如上代码所示,只读属性Id的赋值并没有在构造函数中赋值,毕竟当一个类的只读字段十分多的时候,构造函数也变得复杂。而且在赋值好之后,无法修改,这和我们对只读属性在通常情况下的理解是一致的。另外通过init修饰的好处便是省却了一部分只读属性在操作上的复杂性,使得对象的声明与赋值更加直观。
在合适的场景下选择最好的编程方式,是程序员的一贯追求,千万不要为了炫技而把init当成了茴字的第N种写法到处去问。

record

record是一个非常有用的特性,它是不可变类型,其相等性是通过内部的几个属性来确定的,同时它支持我们以更加方便的方式、像定义值类型那样来定义不可变引用类型。
我们把之前的Product类改成record类型,如下所示:

  1. 1: public record Product
  1. 2: {
  1. 3: public Product(int id, string productName, string description) => (Id, ProductName, Description) = (id, productName, description);
  1. 4:  
  1. 5: public int Id { get; }
  1. 6:  
  1. 7: public string ProductName { get; }
  1. 8:  
  1. 9: public string Description { get; }
  1. 10: }

{ font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }

然后查看一下IL,可以看到record会被编译成类,同时继承了System.Object,并实现了IEquatable泛型接口。
编译器为我们提供的几个重要方法如下:

  • Equals
  • GetHashCode()
  • Clone
  • PrintMembers和ToString()

比较重要的三个方法

Equals:

通过图片中的代码,我们知道比较两个record对象,首先需要比较类型是否相同,然后再依次比较内部属性。

GetHashCode():

record类型通过基类型以及所有的属性及字段的方式来计算HashCode,这在整个继承层次结构中增强了基于值的相等性,也就意味着两个同名同姓的人不会被认为是同一个人

Clone:

这个方法貌似非常简单,实在看不出有什么特别的地方,那么我们通过后面的内容再来解释这个方法。

record在DDD值对象中的应用

record之前的定义方式:

了解DDD值对象的小伙伴应该想到了,record类型的特性非常像DDD中关于值对象的描述,比如不可变性、其相等于是基于其内部的属性的等等,我们先来看下值类型的定义方式。

  1. 1: public abstract class ValueObject
  1. 2: {
  1. 3: public static bool operator ==(ValueObject left, ValueObject right)
  1. 4: {
  1. 5: if (ReferenceEquals(left, null) ^ ReferenceEquals(right, null))
  1. 6: {
  1. 7: return false;
  1. 8: }
  1. 9: return ReferenceEquals(left, null) || left.Equals(right);
  1. 10: }
  1. 11:  
  1. 12: public static bool operator !=(ValueObject left, ValueObject right)
  1. 13: {
  1. 14: return !(left == right);
  1. 15: }
  1. 16:  
  1. 17: protected abstract IEnumerable<object> GetEqualityComponents();
  1. 18:  
  1. 19:  
  1. 20: public override bool Equals(object obj)
  1. 21: {
  1. 22: if (obj == null || obj.GetType() != GetType())
  1. 23: {
  1. 24: return false;
  1. 25: }
  1. 26:  
  1. 27: var other = (ValueObject)obj;
  1. 28:  
  1. 29: return this.GetEqualityComponents().SequenceEqual(other.GetEqualityComponents());
  1. 30: }
  1. 31:  
  1. 32: public override int GetHashCode()
  1. 33: {
  1. 34: return GetEqualityComponents()
  1. 35: .Select(x => x != null ? x.GetHashCode() : 0)
  1. 36: .Aggregate((x, y) => x ^ y);
  1. 37: }
  1. 38: // Other utility methods
  1. 39: }
  1. 40: public class Address : ValueObject
  1. 41: {
  1. 42: public string Street { get; private set; }
  1. 43: public string City { get; private set; }
  1. 44: public string State { get; private set; }
  1. 45: public string Country { get; private set; }
  1. 46: public string ZipCode { get; private set; }
  1. 47:  
  1. 48: public Address(string street, string city, string state, string country, string zipcode)
  1. 49: {
  1. 50: Street = street;
  1. 51: City = city;
  1. 52: State = state;
  1. 53: Country = country;
  1. 54: ZipCode = zipcode;
  1. 55: }
  1. 56:  
  1. 57: protected override IEnumerable<object> GetEqualityComponents()
  1. 58: {
  1. 59: // Using a yield return statement to return each element one at a time
  1. 60: yield return Street;
  1. 61: yield return City;
  1. 62: yield return State;
  1. 63: yield return Country;
  1. 64: yield return ZipCode;
  1. 65: }
  1. 66:  
  1. 67: public override string ToString()
  1. 68: {
  1. 69: return $"Street: {Street}, City: {City}, State: {State}, Country: {Country}, ZipCode: {ZipCode}";
  1. 70: }
  1. 71: }

{ font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }

main方法如下:

  1. 1: static void Main(string[] args)
  1. 2: {
  1. 3: Address address1 = new Address("aaa", "bbb", "ccc", "ddd", "fff");
  1. 4: Console.WriteLine($"address1: {address1}");
  1. 5:  
  1. 6: Address address2 = new Address("aaa", "bbb", "ccc", "ddd", "fff");
  1. 7: Console.WriteLine($"address2: {address2}");
  1. 8:  
  1. 9: Console.WriteLine($"address1 == address2: {address1 == address2}");
  1. 10:  
  1. 11: string jsonAddress1 = address1.ToJson();
  1. 12: Address jsonAddress1Deserialize = jsonAddress1.FromJson<Address>();
  1. 13: Console.WriteLine($"jsonAddress1Deserialize == address1: {jsonAddress1Deserialize == address1}");
  1. 14:  
  1. 15: Console.ReadKey();
  1. 16: }

{ font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }

运行结果如下:

  1. 1: 基于class:
  1. 2: address1: Street: aaa, City: bbb, State: ccc, Country: ddd, ZipCode: fff
  1. 3: address2: Street: aaa, City: bbb, State: ccc, Country: ddd, ZipCode: fff
  1. 4: address1 == address2: True
  1. 5: jsonAddress1Deserialize == address1: True

.csharpcode, .csharpcode pre { font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }

采用record方式定义:

如果有大量的值对象需要我们编写,这无疑是加重我们的开发量的,这个时候record就派上用场了,最简洁的record风格的代码如下所示,只有一行:

  1. 1: public record Address(string Street, string City, string State, string Country, string ZipCode);

{ font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }

IL代码如下图所示,从图中我们也可以看到record类型的对象,默认情况下用到了init来限制属性的只读特性。

main方法代码不变,运行结果也没有因为Address从class变成record而发生改变

  1. 1: 基于record:
  1. 2: address1: Street: aaa, City: bbb, State: ccc, Country: ddd, ZipCode: fff
  1. 3: address2: Street: aaa, City: bbb, State: ccc, Country: ddd, ZipCode: fff
  1. 4: address1 == address2: True
  1. 5: jsonAddress1Deserialize == address1: True

{ font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }

如此看来我们的代码节省的不止一点点,而是太多太多了,是不是很爽啊。

record对象属性值的更改

使用方式如下:

  1. 1: class Program
  1. 2: {
  1. 3: static void Main(string[] args)
  1. 4: {
  1. 5: Address address1 = new Address("aaa", "bbb", "ccc", "ddd", "fff");
  1. 6: Console.WriteLine($"1. address1: {address1}");
  1. 7:  
  1. 8: Address addressWith = address1 with { Street = "############" };
  1. 9:  
  1. 10: Console.ReadKey();
  1. 11: }
  1. 12: }
  1. 13:  
  1. 14: public record Address(string Street, string City, string State, string Country, string ZipCode);

{ font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }

通过ILSpy查看如下所示:

  1. 1: private static void Main(string[] args)
  1. 2: {
  1. 3: Address address1 = new Address("aaa", "bbb", "ccc", "ddd", "fff");
  1. 4: Console.WriteLine($"1. address1: {address1}");
  1. 5: Address address2 = address1.<Clone>$();
  1. 6: address2.Street = "############";
  1. 7: Address addressWith = address2;
  1. 8: Console.ReadKey();
  1. 9: }

{ font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }

由此可以看到record在更改的时候,实际上是通过调用Clone而产生了浅拷贝的对象,这也非常符合DDD ValueObject的设计理念。

参考:

C# 9.0中引入的新特性init和record的使用思考的更多相关文章

  1. Jdk5.0中出现的新特性

    掌握jdk5.0中出现的新特性1.泛型(Generics)2.增强的"for"循环(Enhanced For loop)3.自动装箱/自动拆箱(Autoboxing/unboxin ...

  2. C#6.0 中的那些新特性

    C#6.0 中的那些新特性 前言 VS2015在自己机器上确实是装好了,费了老劲了,想来体验一下跨平台的快感,结果被微软狠狠的来了一棒子了,装好了还是没什么用,应该还需要装Xarmain插件,配置一些 ...

  3. VS2015 C#6.0 中的那些新特性(转载)

    自动属性初始化 (Initializers for auto-properties) 以前我们是这么写的 为一个默认值加一个后台字段是不是很不爽,现在我们可以这样写 只读属性的初始化(Getter-o ...

  4. VS2015 C#6.0 中的那些新特性(转自http://www.cnblogs.com/henryzhu/p/new-feature-in-csharp-6.html)

    自动属性初始化 (Initializers for auto-properties) 以前我们是这么写的 为一个默认值加一个后台字段是不是很不爽,现在我们可以这样写 只读属性的初始化(Getter-o ...

  5. C#6.0中10大新特性的应用和总结

    微软发布C#6.0.VS2015等系列产品也有一段时间了,但是网上的教程却不多,这里真对C#6.0给大家做了一些示例,分享给大家.   微软于2015年7月21日发布了Visual Studio 20 ...

  6. Android3.0中ActionBar的新特性

    1. ActionBar(活动栏)替代了显示在屏幕顶端的标题栏.主要负责显示菜单,widget,导航等功能,主要包括:@  显示选项菜单中的菜单项到活动栏:@  添加可交互的视图到活动栏作为活动视图: ...

  7. VS2015 C#6.0 中的那些新特性

    本人个人博客原文链接地址为http://aehyok.com/Blog/Detail/66.html. 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok ...

  8. Android 7.0(牛轧糖)新特性

    Android 7.0(牛轧糖)新特性 谷歌正式在I/O大会现场详细介绍了有关Android 7.0的大量信息.目前,我们已经知道,新一代Android操作系统将支持无缝升级,能够通过Vulkan A ...

  9. Xcode中StoryBoard Reference 新特性的使用

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

随机推荐

  1. sort(hdu oj 1425)计数排序和快速排序

    Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0 < n,m < 1000000),第二行包含n个各不 ...

  2. 我要进大厂之大数据ZooKeeper知识点(1)

    01 让我们一起学大数据 老刘又回来啦!在实验室师兄师姐都找完工作之后,在结束各种科研工作之后,老刘现在也要为找工作而努力了,要开始大数据各个知识点的复习总结了.老刘会分享出自己的知识点总结,一是希望 ...

  3. 神秘、常用、多变的Binder

    今天说说神秘又常用又多变的Binder~ Binder是什么 Binder通信过程和原理 在Android中的应用 Binder优势 Binder是什么 先借用神书<Android开发艺术探索& ...

  4. 如何在PDF文档上加水印

    当我们需要传输一些比较重要的文件时,往往会选择将文档转换为PDF文件,避免其他人复制.更改文档的内容. pdfFactory不仅可以为用户提供快速创建PDF的功能,同时还提供了添加水印的功能.有了水印 ...

  5. 思维导图软件iMindMap的使用方法

    从手绘的思维导图再到各种各样的思维导图的软件,思维导图的高效性大家都体会到了.思维导图软件iMindMap在众多导图软件中是最受欢迎的之一,下面就给大家分享一下思维导图怎么画: 首先我要教给大家的是如 ...

  6. 如何将MathType恢复出厂设置

    必大家都知道,我们日常使用的手机是自带恢复出厂设置功能的,其实除了手机,咱们今天要说的这款公式编辑器MathType,也是可以进行恢复出厂设置操作的哦,下面就让小编给大家介绍一下吧. 一.打开Math ...

  7. Ⅶ. Policy Gradient Methods

    Dictum:  Life is just a series of trying to make up your mind. -- T. Fuller 不同于近似价值函数并以此计算确定性的策略的基于价 ...

  8. Java集合【3】-- iterable接口超级详细解析

    目录 iterable接口 1. 内部定义的方法 1.1 iterator()方法 1.2 forEach()方法 1.3 spliterator()方法 总结 iterable接口 整个接口框架关系 ...

  9. spring mvc 文件上传报“由于没有提供multi-part配置,无法处理parts”

    在使用springMVC进行文件上传时,报了HTTP 500的错. 才发现原来是在springmvc.xml配置文件中,multipart中的id写错了. 错误代码: <!-- 配置文件解析器- ...

  10. MySQL对数据 对表 对数据操作

    ------------恢复内容开始------------ MySQL 数据库的操作 创建 create database 数据库名; 指定字符集 create database 数据库名 char ...