Take the following code:
IFoo foo = new FooImplementation();
The identifier foo
has two types:
IFoo
- This is the type the compiler will enforce. I will only be able to call methods that are part of the IFoo
contract, otherwise I'll get a compiler error.FooImplementation
- This is the type as known by the runtime. I can downcast foo
to a FooImplementation
at runtime, and then call non-IFoo methods of FooImplementation
.My question: What is the proper terminology for these two types. I could swear in school we were taught that IFoo
is the identifier's static type and FooImplementation
is its dynamic type, but after much searching on Google I can't seem to find any reference to this.
Rules for naming identifiers A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores. The first letter of an identifier should be either a letter or an underscore. You cannot use keywords like int , while etc. as identifiers.
An identifier is a name that identifies (that is, labels the identity of) either a unique object or a unique class of objects, where the "object" or class may be an idea, physical countable object (or class thereof), or physical noncountable substance (or class thereof).
I would call IFoo
and FooImplementation
the compile-time and run-time types, respectively. This language is used by C# spec, for example, when talking about virtual methods (section 1.6.6.4):
When a virtual method is invoked, the run-time type of the instance for which that invocation takes place determines the actual method implementation to invoke. In a nonvirtual method invocation, the compile-time type of the instance is the determining factor.
I agree with Mike Z. The usual terminology in C# is "compile time type" and "runtime type".
"Static type" and "dynamic type" are entirely reasonable terms but I would avoid them in the context of C#. "Static type" could too easily be confused with "static class", a class which can only contain static methods. And "dynamic type" can too easily be confused with the dynamic type feature added to C# 4.
The first is the Declared Type. The second is the Concrete Type.
...at least that's what I call them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With