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 for the meaning and here's what I got:
Implicit
"Something that is implicit is expressed in an indirect way."
"If a quality or element is implicit in something, it is involved in it or is shown by it;"
Explicit
"Something that is explicit is expressed or shown clearly and openly, without any attempt to hide anything"
"If you are explicit about something, you speak about it very openly and clearly."
I would like to understand it in C#.
Thanks for your help.
Cheers
additional info:
Here is a part of sentence in the book what I'm reading now which has this word "implicit"
"This means that Area and Occupants inside
AreaPerPerson( )
implicitly refer to the copies of those variables found in the object that invokesAreaPerPerson( )
"
I quite don't understand what this sentence here trying to say.
Implicit conversion is the conversion in which a derived class is converted into a base class like int into a float type. Explicit conversion is the conversion that may cause data loss. Explicit conversion converts the base class into the derived class.
Explicit describes something that is very clear and without vagueness or ambiguity. Implicit often functions as the opposite, referring to something that is understood, but not described clearly or directly, and often using implication or assumption.
There are two type of type conversion: implicit and explicit type conversion in C. Implicit type conversion operates automatically when the compatible data type is found. Explicit type conversion requires a type casting operator.
Implicit type conversion in C language is the conversion of one data type into another datatype by the compiler during the execution of the program. It is also called automatic type conversion.
The implicit
and explicit
keywords in C# are used when declaring conversion operators. Let's say that you have the following class:
public class Role { public string Name { get; set; } }
If you want to create a new Role
and assign a Name
to it, you will typically do it like this:
Role role = new Role(); role.Name = "RoleName";
Since it has only one property, it would perhaps be convenient if we could instead do it like this:
Role role = "RoleName";
This means that we want to implicitly convert a string to a Role
(since there is no specific cast involved in the code). To achieve this, we add an implicit conversion operator:
public static implicit operator Role(string roleName) { return new Role() { Name = roleName }; }
Another option is to implement an explicit conversion operator:
public static explicit operator Role(string roleName) { return new Role() { Name = roleName }; }
In this case, we cannot implicitly convert a string to a Role
, but we need to cast it in our code:
Role r = (Role)"RoleName";
In general
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With