Types and Initialization
Before we conclude the discussion of type members, there are two methods that bear special discussion. Types are allowed to provide a distinguished method that is called when the type is first initialized. This type initializer is simply a static method with a well-known name (.cctor). A type can have at most one type initializer, and it must take no parameters and return no value. Type initializers cannot be called directly; rather, they are called automatically by the CLR as part of the type's initialization. Each programming language provides its own syntax for defining a type initializer. In VB.NET, you simply write a Shared (per type) subroutine named New. In C#, you must write a static method whose name is the same ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access