-2

According to this article:

it is important to remember that C# is a statically typed language; which leaves no room for variant types

Which seems correct... However doesn't the Dynamic data type break that rule? Maybe I am missing some subtle difference that I am unaware of but a Dynamic data type seems like a real Variant (Like JavaScript or VBA) to me?

Anthony Griggs
  • 1,469
  • 2
  • 17
  • 39

1 Answers1

2

Under the covers dynamic is compiled to System.Object and the compiler writes patterns that are strongly typed, and do much of the work of the dispatch at runtime. Hence, C# (truly the CLR) is still strongly typed, but with some asterisks.

var here in C# is all about type inference and thats what that article is discussing.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • I don't think it matters what compiler does under the hood. Type checking on dynamic variable is perfromed at runtime, so it's not static type checking (which means it's performed at compile time). – Evk Nov 02 '21 at 13:53
  • He was speaking of in comparison to var... however I meant it as in comparison to a real Variant like JavaScript. Since Dynamic compiles at runtime... that seems like a Variant to me. – Anthony Griggs Nov 02 '21 at 16:57
  • 1
    @AnthonyGriggs yea dynamic is like variant – Daniel A. White Nov 02 '21 at 17:48