Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


use of operator overloading of implicit & explicit operators?



use of operator overloading of implicit & explicit operators?..

Answer / karthikeyant

Implicit:

By eliminating unnecessary casts, implicit conversions can
improve source code readability. However, because implicit
conversions can occur without the programmer's specifying
them, care must be taken to prevent unpleasant surprises.
In general, implicit conversion operators should never
throw exceptions and never lose information so that they
can be used safely without the programmer's awareness. If a
conversion operator cannot meet those criteria, it should
be marked explicit.

class MyType
{
public static implicit operator int(MyType m)
{
// code to convert from MyType to int
}
}

MyType x;
// implicitly call MyType's MyType-to-int conversion
operator
int i = x;

Explicit:
declares a user-defined type conversion operator that must
be invoked with a cast. For example, this operator converts
from a class called Fahrenheit to a class called Celsius:

// Must be defined inside a class called Farenheit:
public static explicit operator Celsius(Farenheit f)
{
return new Celsius((5.0f/9.0f)*(f.degrees-32));
}

Farenheit f = new Farenheit(100.0f);
Celsius c = (Celsius)f;

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More C Sharp Interview Questions

What is the difference between CONST and READONLY?

0 Answers   BirlaSoft,


Can you store different types in an array in c#?

0 Answers  


What is manifest ?

3 Answers   Digital GlobalSoft,


Which framework is best for desktop application?

0 Answers  


What is the difference between system.string and system.text.stringbuilder classes?

0 Answers  


Explain the difference between Response.Write () and Response.Output.Write ().

0 Answers   Atos Origin,


How C# 4.0 supports dynamic programming language?

0 Answers  


What is Abstraction?

8 Answers   Google, HCL, IBM, MAHINDRA, Tech Mahindra,


Which debugging tools you can use in the .NET ssSDK?

0 Answers   Siebel,


What are the differences between events and delegates in c#?

0 Answers  


What's the difference between a method and a procedure?

0 Answers  


What is list collection in c#?

0 Answers  


Categories