explicit and implicit c#

前端 未结 7 2024
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 13:31

I\'m new to C# and learning new words. I find it difficult to understand what\'s the meaning of these two words when it comes to programming c#. I looked in the dictionary

7条回答
  •  情歌与酒
    2020-12-07 13:55

    Implicit can be taken as implied, but explicit means that you state it must be done yourself. Like with casts. Here is an implicit cast:

    int implicit;
    implicit = 7.5;
    

    The value '7.5' will implicitly be cast as an int. This means the compiler does it for you.

    Here is explicit:

    int explicit;
    explicit = (int)7.5;
    

    Here you tell the compiler that you want it cast. You explicitly declare the conversion. Hope that helps. Source: http://cboard.cprogramming.com/cplusplus-programming/24371-implicit-explicit.html

提交回复
热议问题