none
'struct' value type?!? RRS feed

  • Question

  • Hello All,
    I am little confused about 'struct' bieng a value type.

    As I understand 'struct' is a collection of objects and a instance of a 'struct' should contain a "reference" to the collection. So 'struct' should be a reference type.

    Thanks for clarification.
    Monday, July 27, 2009 7:58 AM

Answers

  • No, struct is definitely a value type.  Your mental model of "a collection of objects" is not accurate.  A struct has fields.  The equivalent of a struct that's not a value type is a class.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, July 31, 2009 12:52 PM
    Monday, July 27, 2009 10:38 AM
    Moderator

All replies

  • Hi,
    "As I understand 'struct' is a collection of objects  "
    the collection of objects  doesn’t mean it will be reference or value, you who decide which one you will need, so if you need a reference mechanism then use class if you need value mechanism just use struct so this matter of how you will handle your type inside your application

     

     


    We are volunteers, if the reply help you mark it as your answer. thanks!!
    My Blog
    Monday, July 27, 2009 8:20 AM
  • No, struct is definitely a value type.  Your mental model of "a collection of objects" is not accurate.  A struct has fields.  The equivalent of a struct that's not a value type is a class.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Friday, July 31, 2009 12:52 PM
    Monday, July 27, 2009 10:38 AM
    Moderator