• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 970
  • Last Modified:

Explicit,Implicit keyword usage in C#

What is the use of Explicit as well as Implicit keyword in c#?
0
Rahamathulla_J
Asked:
Rahamathulla_J
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0
 
multithreadingCommented:
Read the article for sample code and usage/syntax.

Once you have the syntax, know this ...

You use "explicit" when you want the person to use a cast to invoke your type conversion.
You use "implicit" when you want the type conversion to happen silently.
Use the built-in types as your guide. For example, you don't need an explicit cast to go from short to int, or int to long, but you do need an explicit cast to go from long to int, or int to short. This is because in one direction information loss is unlikely, while in the other direction it is highly probable. So, loss of information is one reason to require a cast. The other reason is to prevent any magical errors: If a reasonable person using your class could be surprised to learn that he had accidently changed types, you definately should have used Explicit.

0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now