Welcome to Shaun Luttin's public notebook. It contains rough, practical notes. The guiding idea is that, despite what marketing tells us, there are no experts at anything. Sharing our half-baked ideas helps everyone. We're all just muddling thru. Find out more about our work at bigfont.ca.

Predefined vs User-Defined

Tags: c#

Predefined

In version 5.0 of the C# language specification (hereafter called "the spec") the term predefined occurs 102 times and its hyphenated synonym pre-defined occurs 14 times. The spec uses it in three contexts:

  1. predefined types,
  2. predefined conversions, and
  3. predefined operators.

What exactly does it mean for something in C# to be predefined? Unfortunately, the spec does not provide a clear, formal definition. From looking at how the spec uses the term, I've come up with the following definition. To me, something is predefined if the spec defines (i.e. specifies) it and guarantees that it will be present in any C# implementation (such as mscorlib.)

User-Defined

The term user-defined occurs 142 times in the spec and another 4 times without the hyphen as user defined. The spec talks about user-defined types, conversions, operators, indexers, and constructors.

  1. types "C# supports both user-defined reference types and value types" (p. 1)
  2. conversions "C# allows the pre-defined ... conversions to be augmented by user-defined conversions." (p. 119)
  3. operators "Operator overloading permits user-defined operator implementations..." (p. 7)
  4. indexers "user-defined indexing is supported through indexers." (p. 136)
  5. constructors "user-defined constructors must call the default constructor." (p. 330)

Again, the spec does not give a formal definition of the term user-defined. From the context, something is user-defined if the spec does not define it. So user-defined includes .NET Framework Libraries and assemblies that you, I, or anyone else writes.

Am I mistaken? Let me know at https://twitter.com/dicshaunary