c# - What is the difference between explicit and implicit type casts? -


Would you please tell the difference between clear and underlying type Can you? This is a bit tricky because the "cast" syntax in C # is actually

Things (Cast, Primitive Convert, Bespoke Convert, etc.)

In an underlying cast, there is a clear context-protection conversion between the two:

  list From & lt; Integer & gt; L = new list & lt; Int & gt; (); IList & LT; Integer & gt; IL = L;  

The compiler can prove that this static analysis ( list & lt; int & gt; is always a IList & lt; int & gt;

With a clear artist, either you are saying the compiler that you know more than - "Please believe me, but Check anyway ":

  from the list & lt; Integer & gt; L = new list & lt; Int & gt; (); IList & LT; Integer & gt; IL = L; & Lt; Integer & gt; L2 = (list & lt; int & gt;);  

Although this artist is possible , then the compiler will not accept that all IList & lt; Int & gt; In fact the list & lt; Int & gt; - So let us tell it to tell it.


In an inherent primitive conversion (provided by language spec), it is generally assumed that a safe, non-risky, non-loss (warning: see John's comment ) Conversion:

  int i = 1; Float F = i;  

With a clear primitive conversion, it is possible that the conversion data may be lost, or it is unclear:

  Float F = 1; Int i = (int) f;  

With the Ospec Operator, all the bets are off, and you have to see the documentation. This can be a reference-cast, or it may anything adhere to the same rules as primitive conversions (example: decimal ) or it's random Anything from:

  XNamespace ns = "http: // abc / def"; // The built-in XAttribute attrib = GetAttrib (); Int i = (int) attrib; // clear (extract text from attrib value and parses for integer //)  

Both of these custom-code code are context-specific.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -