Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 45147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:45:48+00:00 2026-05-10T15:45:48+00:00

In Jesse Liberty’s Learning C# book, he says "Objects of one type can be

  • 0

In Jesse Liberty’s Learning C# book, he says

"Objects of one type can be converted into objects of another type. This is called casting."

If you investigate the IL generated from the code below, you can clearly see that the casted assignment isn’t doing the same thing as the converted assignment. In the former, you can see the boxing/unboxing occurring; in the latter you can see a call to a convert method.

I know in the end it may be just a silly semantic difference–but is casting just another word for converting. I don’t mean to be snarky, but I’m not interested in anyone’s gut feeling on this–opinions don’t count here! Can anyone point to a definitive reference that confirms or denies if casting and converting are the same thing?

    object x;     int y;          x = 4;          y = ( int )x;          y = Convert.ToInt32( x ); 

Thank you

rp

Note added after Matt’s comment about explicit/implicit:

I don’t think implicit/explicit is the difference. In the code I posted, the change is explicit in both cases. An implicit conversion is what occurs when you assign a short to an int.

Note to Sklivvz:

I wanted confirmation that my suspicion of the looseness of Jesse Liberty’s (otherwise usually lucid and clear) language was correct. I thought that Jesse Liberty was being a little loose with his language. I understand that casting is routed in object hierarchy–i.e., you can’t cast from an integer to a string but you could cast from custom exception derived from System.Exception to a System.Exception.

It’s interesting, though, that when you do try to cast from an int to a string the compiler tells you that it couldn’t "convert" the value. Maybe Jesse is more correct than I thought!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:45:48+00:00Added an answer on May 10, 2026 at 3:45 pm

    The simple answer is: it depends.

    For value types, casting will involve genuinely converting it to a different type. For instance:

    float f = 1.5f; int i = (int) f; // Conversion 

    When the casting expression unboxes, the result (assuming it works) is usually just a copy of what was in the box, with the same type. There are exceptions, however – you can unbox from a boxed int to an enum (with an underlying type of int) and vice versa; likewise you can unbox from a boxed int to a Nullable<int>.

    When the casting expression is from one reference type to another and no user-defined conversion is involved, there’s no conversion as far as the object itself is concerned – only the type of the reference ‘changes’ – and that’s really only the way that the value is regarded, rather than the reference itself (which will be the same bits as before). For example:

    object o = 'hello'; string x = (string) o; // No data is 'converted'; x and o refer to the same object 

    When user-defined conversions get involved, this usually entails returning a different object/value. For example, you could define a conversion to string for your own type – and this would certainly not be the same data as your own object. (It might be an existing string referred to from your object already, of course.) In my experience user-defined conversions usually exist between value types rather than reference types, so this is rarely an issue.

    All of these count as conversions in terms of the specification – but they don’t all count as converting an object into an object of a different type. I suspect this is a case of Jesse Liberty being loose with terminology – I’ve noticed that in Programming C# 3.0, which I’ve just been reading.

    Does that cover everything?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm watching this video post (by Jon Galloway and Jesse Liberty) about Building a
I tried to copy this example from this Multiprocessing lecture by jesse noller (as
I'm using KRL to inject elements into twitter timeline statuses similar to Jesse Stay's
In Jesse Liberty's Programming C# (p.142) he provides an example where he casts an
I'm learning C++ with codeblocks and I'd like to ask if you can post
After all what I've read on this topic, I know that there is no
i am using javax.Mail api with authenticator, but this below code giving Access restriction:
I want to parse the JSON string below into an associative array, sort it
I'm new to reporting services so this question might be insane. I am looking
I'm rewriting a Bash script I wrote into Python. The crux of that script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.