Is C# a strongly typed or a weakly typed language?

Presented as a dialogue, as is my wont!

Is C# a strongly typed or a weakly typed language?


That is unhelpful.

I don’t doubt it. Interestingly, if you rephrased the question as an “and” question, the answer would be the same.

What? You mean, is C# a strongly typed and a weakly typed language?

Yes, C# is a strongly typed language and a weakly typed language.

I’m confused.

Me too. Perhaps you should tell me precisely what you mean by “strongly typed” and “weakly typed”.

Um. I don’t actually know what I mean by those terms, so perhaps that is the question I should be asking. What does it really mean for a language to be “weakly typed” or “strongly typed”?

“Weakly typed” means “this language uses a type verification system that I find distasteful“, and “strongly typed” means “this language uses a type system that I find attractive“.

No way!

Way, dude.


These terms are meaningless and you should avoid them. Wikipedia lists eleven different meanings for “strongly typed”, several of which contradict each other. Any time two people use “strongly typed” or “weakly typed” in a conversation about programming languages, odds are good that they have two subtly or grossly different meanings in their heads for those terms, and are therefore automatically talking past each other.

But surely they mean something other than “unattractive” or “attractive”!

I do exaggerate somewhat for comedic effect. So lets say: a more-strongly-typed language is one that has somerestriction in its type system that a more-weakly-typed language it is being compared to lacks. That’s all you can really say without more context.

How can I have sensible conversations about languages and their type systems then?

You can provide the missing context. Instead of using “strongly typed” and “weakly typed”, actually describe the restriction you mean. For example, C# is for the most part a statically typed language, because the compiler determines facts about the types of every expression. C# is for the most part a type safe language because it prevents values of one static type from being stored in variables of an incompatible type (and other similar type errors). And C# is for the most part memory safe language because it prevents accidental access to bad memory.

Thus, someone who thinks that “strongly typed” means “the language encourages static typing, type safety and memory safety in the vast majority of normal programs” would classify C# as a “strongly typed” language. C# is certainly more strongly typed than languages that do not have these restrictions in their type systems.

But here’s the thing: because C# is a pragmatic language there is a way to override all three of those safety systems. Cast operators and “dynamic” in C# 4 override compile-time type checking and replace it with runtime type checking, and “unsafe” blocks allow you to turn off type safety and memory safety should you need to. Someone who thinks that “strongly typed” means “the language absolutely positively guarantees static typing, type safety and memory safety under all circumstances” would quite rightly classify C# as “weakly typed”. C# is not as strongly typed as languages that do enforce these restrictions all the time.

So which is it, strong or weak? It is impossible to say because it depends on the point of view of the speaker, it depends on what they are comparing it to, and it depends on their attitude towards various language features. It’s therefore best to simply avoid these terms altogether, and speak more precisely about type system features.

Next time on FAIC: What happens when a dynamic call’s method group has a single member?


17 thoughts on “Is C# a strongly typed or a weakly typed language?

  1. Pingback: Seeking clarification on apparent contradictions regarding weakly typed languages | Everyday I'm coding

  2. Brilliant explanation, thanks. I was so confused by the various “definitions” of strong and weak typing because they so often contradict each other. This put my mind at ease.

  3. Pingback: What is late binding? | Fabulous adventures in coding

  4. Pingback: What is “duck typing”? | Fabulous adventures in coding

  5. Pingback: How to: Seeking clarification on apparent contradictions regarding weakly typed languages | SevenNet

  6. Pingback: How to: Seeking clarification on apparent contradictions regarding weakly typed languages #answer #solution #development | IT Info

  7. C# in strongly type mode:
    int i = 0;

    C# in weakly type mode:
    object i = 0;

    try to stick in strongly type mode, unless you have strong reason not to do so

  8. Pingback: » Python:Seeking clarification on apparent contradictions regarding weakly typed languages

  9. Pingback: ُسی‌شارپ strongly-typed است یا weakly-typed؟

  10. Pingback: سی‌شارپ strongly-typed است یا weakly-typed؟

  11. Pingback: Strong and week typed | kuangmingchen

  12. Pingback: প্রোগ্রামিংয়ের টুকিটাকি -২ঃ টাইপ সিস্টেম (Type System)

  13. Pingback: The Beginning (An overview of .NET, C# Visual Studio and the debugger) – Dev Days

  14. Pingback: 寻求关于弱类型语言的明显矛盾的澄清 | CODE问答

  15. Pingback: Seeking clarification on apparent contradictions regarding weakly typed languages - ExceptionsHub

  16. This is a common problem with language, one that needs to be addressed at some point.

    I do not care to research the etymology (and I would never believe anything Wikipedia says on the matter) , but I have little doubt that the history of the terms has had key significant changes in meaning over the years, as well as points where we could see the terms branching off in different directions.

    Language changes over time, often to the chagrin of the older generation. Irony has been rapidly changing to mean “whatever the speaker wants it to mean at the moment”, the same can be said for literally… there are other words out there that suffer from the same issue but the problem is that language changes.

    Why does language change? Contempt, people didn’t like that their language was labeled “weak typed” and claimed it was “strong typed” while the other language was actually “weak typed”… and then we have the other issue, people just do not know what the words mean and don’t care to learn…

  17. Thanks for the article. So as I understand C# is more strongly typed than some languages ( eg: JavaScript, Python – because those are not statically typed ) . So I am curious to know which are the languages those are even more strongly typed than C# ? (probably the ones that do not support late binding or casting/explicit conversions)

Leave a Reply to select Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s