explicit and implicit c#

前端 未结 7 2013
爱一瞬间的悲伤
爱一瞬间的悲伤 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:37

    In general

    • Implicit: something is being done for you automatically.
    • Explicit: you've written something in the source code to indicate what you want to happen.

    For example:

    int x = 10;
    long y = x; // Implicit conversion from int to long
    int z = (int) y; // Explicit conversion from long to int
    

    Implicit and explicit are used quite a lot in different contexts, but the general meaning will always be along those lines.

    Note that occasionally the two can come together. For instance:

    int x = 10;
    long y = (long) x; // Explicit use of implicit conversion!
    

    (An explicit conversion is one which has to be stated explicitly; an implicit version is one which can be used implicitly, i.e. without the code having to state it.)

提交回复
热议问题