What does strongly typed means in .NET framework?

后端 未结 5 2249
悲哀的现实
悲哀的现实 2020-12-28 15:11

This morning was going through a book where I found a paragraph as stated below :

Each data field in a table is a strongly typed data member, fully compliant wit

相关标签:
5条回答
  • 2020-12-28 15:53

    No. It means that 1 and "1" (or any other number and string for that matter) are different values that cannot be casually interchanged in expressions.

    0 讨论(0)
  • 2020-12-28 15:55

    For e.g you cannot Multiply or Divide two different types i.e String vs Integer

    var answer = 1 * "1"; // you cannot do this
    

    You have to explicity cast it, this is known as strongly typed

    where as if you see in php

    $x = "3" * 1; // is correct in php
    

    So here you dont need to explicitly cast it.

    0 讨论(0)
  • 2020-12-28 15:55

    When we say something is strongly typed we mean that the type of the object is known and available.

    Let say I have a function like following

    public int Add(int a, int b){
     return a+b;
    }
    

    We can call this function like

    int result = Add(5,4);
    

    But we can not do like following

    int result = Add(5.2,4.5); // We will get here compilation error.
    

    C# (and C++ and many other languages) is strongly typed because the compiler will detect and flag these errors at compilation time.

    See here

    0 讨论(0)
  • 2020-12-28 15:57

    This means, if there are two variables of different types, you have to cast them, to make an operation executable.

    Else it will throw an exception.

    0 讨论(0)
  • 2020-12-28 15:58

    "fully compliant with .NET’s Common Type System" means that the data types are usable in any .NET language. So if you created a class that exposes a property in c# that is CTS compliant, that class can be consumed from say VB.net.

    "Each data field in a table is a strongly typed data member" means that you can rely on the type of the value in the table, and you would have to cast it to another type if that was required. You can't do implicit casting.

    0 讨论(0)
提交回复
热议问题