locked
Casting the Object type RRS feed

  • Question

  • What is the correct syntax to cast an Object into an int?

    For example, ListViewItem's Tag property is of type Object.  After the property is set with an int value, how do I cast it back to an int value?

    Monday, September 18, 2006 10:11 AM

Answers

  • int n = (int)item->Tag;
    Monday, September 18, 2006 12:09 PM
  • You can also do a static_cast:

     

    int n = static_cast<int>(item->Tag);

     

    Monday, September 18, 2006 1:17 PM

All replies

  • int n = (int)item->Tag;
    Monday, September 18, 2006 12:09 PM
  • You can also do a static_cast:

     

    int n = static_cast<int>(item->Tag);

     

    Monday, September 18, 2006 1:17 PM