When should we use implicit and explicit operators in C #?

What is the use of these operators?

+5
source share
2 answers

Basically, if you want to provide conversions between types. LINQ to XML provides good examples ... There is implied conversion from string to XName, so you can write:

XName name = "element";

but there is an explicit conversion from XAttributeto int(and many other types), so you need to include in your code:

int value = (int) element.Attribute("age");

, - ; LINQ to XML , . .

+10

. MSDN.

+3

All Articles