Fabulous Adventures In Coding : Representation and Identity(blogs.msdn.com)

submitted by schalkvanwykschalkvanwyk(1335) 2 years, 9 months ago

Questions about the C# cast operator, the most frequent question I get is: short sss = 123; object ooo = sss; // Box the short. int iii = (int) sss; // Perfectly legal. int jjj = (int) (short) ooo; // Perfectly legal int kkk = (int) ooo; // Invalid cast exception?! Why? Why? Because a boxed T can only be unboxed to T. (*) Once it is unboxed, it’s just a value that can be cast as usual, so the double cast works just fine. Many people find this restriction grating; they expect to be able to cast a boxed thing to anything that the unboxed thing could have been cast to. There are ways to do that, as we’ll see, but there are good reasons why the cast operator does what it does.

add a comment |category: |Views: 4

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

No comments so far

information Login or create an account to comment on this story