Solved

Explicit,Implicit keyword usage in C#

Posted on 2007-11-20
2
961 Views
Last Modified: 2013-12-17
What is the use of Explicit as well as Implicit keyword in c#?
0
Comment
Question by:Rahamathulla_J
2 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20319290
0
 
LVL 7

Accepted Solution

by:
multithreading earned 250 total points
ID: 20319327
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Entity Framework 7 43
SqlDependency to get update from sql to my c# app 2 40
Moving code from one TFS branch to another 3 25
parsing JSON help 1 9
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question