Solved

Explicit,Implicit keyword usage in C#

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

11 Experts available now in Live!

Get 1:1 Help Now