What is the correct terminology for each type of identifier?

Take the following code:

IFoo foo = new FooImplementation(); 

The identifier foo has two types:

  • IFoo is the type that the compiler will execute. I can only call methods that are part of the IFoo contract, otherwise I will get a compiler error.
  • FooImplementation is a type known at runtime. I can disable foo before FooImplementation at runtime, and then call non-IFoo FooImplementation .

My question is: What is the correct terminology for these two types. I could swear that we were taught at school that IFoo is a static type of identifier, and FooImplementation is its dynamic type, but after a long search on Google I can not find links to this.

+6
source share
3 answers

I would call IFoo and FooImplementation compile time and FooImplementation types, respectively. This language is used by the C # specification, for example, when it comes to virtual methods (section 1.6.6.4):

When a virtual method is called, the run-time type of the instance for which this call is made determines the actual method implementation for the call. In the invocation of a non-virtual method, the type of instance compilation time is the determining factor.

+6
source

The first is the Declared Type. The second is the concrete type.

... at least what I call them.

+4
source

I agree with Mike Z. The usual terminology in C # is โ€œcompile time typeโ€ and โ€œrun time typeโ€.

"Static type" and "dynamic type" are perfectly reasonable terms, but I would avoid them in a C # context. The "static type" could be easily confused with the "static class", a class that can only contain static methods. And the "dynamic type" can be easily confused with the dynamic type function added in C # 4.

+4
source

All Articles