Solved

Explicit,Implicit keyword usage in C#

Posted on 2007-11-20
2
960 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get list of word ducuments in a folder 10 36
Memory Usage 2 50
How would you add MULTITHREADING to the attached C# code? 4 52
C# guarantee sql connection close 6 30
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now