classTest:iequatable<test> { Public intAA {Get;Set; } Public stringbb {Get;Set; } Public BOOLCC {Get;Set; } Public stringDD; PublicTeststringdd) { This. DD =DD; } Public BOOLEquals (Test other) {return( This. AA = = Other.aa && This. bb = = Other.bb && This. cc = = other.cc && This. DD = =other.dd); } } classProgram {Static voidMain (string[] args) {Test a=NewTest" A") {AA =1, BB =" One", CC =true, DD =" A" }; Test B=NewTest" A") {AA =1, BB =" One", CC =true, DD ="224" }; Console.WriteLine (A.equals (b)); ReadLine (); } }
In the code above, there are two ways to initialize an object's properties or fields in the same place. As you can see, constructors are executed first. The value assigned by the assignment statement in the curly brace {} is the final value of the object initialization.
In fact:
Test B =NewTest" A") {AA =1, BB =" One", CC =true, DD ="224"}; equivalent to test b=NewTest" A"); B.aa=1; B.BB =" One"; b.cc =true; B.DD ="224";
C # Object Initialization