Having a little more context would help in answering your question ("[...] define the idea of 'type' in a C#.Net context[...]
"), but here's a quick stab at it. The concept of a type in .NET comes from object-oriented programming, and is a generalization of the datatype concept from pre-OOP programming languages. In its simplest form, you could say that...
A type is a named template for a
structure, instances of which hold data and/or behavior.
Answers to questions in EDIT section:
[...] how does the CLR treat the idea of a type?
I don't know exactly what you mean by that, but a type in the CLR - the 'named template' in my definition above - is physically stored as CIL and is represented in the system by an object which itself (like all objects) is of a type.
In this case, that type is named, sure enough, System.Type
. (In case you're curious, this type is physically stored in the mscorlib
assembly.) I know that I'm using a term in its own definition, but it's hard not to, since the concept is inherently recursive.
[...] does the CLR need to implicitly cast null to a string in the
assignment string s = null? Answers so far imply no, it does not, but
what allows that assignment? Is null just treated as a special case
here?
Yes, it is a special case and no, neither the compiler nor the CLR cast null
to a string
(or anything else). null
has no type (1) and cannot be converted to any type -- it is a special "value" that denotes the absence of a value (2) and is thus assignable to a variable of any reference type (3).
(1) Depending on where you look, it may or may not be of type "null type".
(2) Such a value would be a reference to an instance of that type.
(3) There are two kinds of types -- reference types and value types -- and null
truly only applies to the former kind. It can appear in source code (e.g. int? i = null;
) as being assigned to a variable of a nullable value type, but that's just syntactic sugar and what happens behind the scenes is very different and only tangentially related to this discussion.