Anonymous types in VB NET – Key Property

Key properties have three main characteristics:

  • Only the values of key properties are compared in order to determine whether two instances are equal;
  • The values of key properties are read-only;
  • Only key property values are included in the compiler-generated hash code algorithm for an anonymous type;

Unit test example:

Result:

Anonymous type test results

Anonymous type test results

About Samuele Resca

Samuele Resca is an Microsoft MVP Visual Studio and Development Technologies, Software Engineer, specializing mainly on ASP.NET MVC and in general about everything that revolves around the web. Samuele was born in 1994, and works as a software developer @ YOOX NET-A-PORTER Group He loves the MVC frameworks, ASP.NET MVC, Javascript, Node.js and Typescript.