none
types in .net RRS feed

  • Question

  • why  we put enum & struct in value types
    • Moved by Barry Wang Monday, December 10, 2012 10:36 AM .NET types (From:Visual Studio Setup and Installation)
    Sunday, December 9, 2012 5:07 PM

Answers

  • Hope this article can help you.

    http://msdn.microsoft.com/en-us/library/34yytbws%28v=vs.90%29.aspx

    User-defined value types

    Your language will provide ways to define your own value types, which derive from System.ValueType or System.Enum. If you want to define a type representing a value that is small, such as a complex number (using two floating-point numbers), you might choose to define it as a value type because you can pass the value type efficiently by value. If the type you are defining would be more efficiently passed by reference, you should define it as a class instead.
     


    Regards,
    Christian HL
    Microsoft Online Community Support


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.



    Thursday, December 13, 2012 6:02 AM

All replies

  • Perhaps this article and discussion will help...

    http://lamahashim.blogspot.com/2010/04/net-framework-value-types.html

    Sunday, December 9, 2012 10:53 PM
  • Because microsoft thought that .NET developers should have a way to create Value Types. Since ValueType cannot be inherited, the only way left for developer to create Value type objects is via struct and enums.

    Please mark this post as answer if it solved your problem. Happy Programming!

    Tuesday, December 11, 2012 8:50 AM
  • Hope this article can help you.

    http://msdn.microsoft.com/en-us/library/34yytbws%28v=vs.90%29.aspx

    User-defined value types

    Your language will provide ways to define your own value types, which derive from System.ValueType or System.Enum. If you want to define a type representing a value that is small, such as a complex number (using two floating-point numbers), you might choose to define it as a value type because you can pass the value type efficiently by value. If the type you are defining would be more efficiently passed by reference, you should define it as a class instead.
     


    Regards,
    Christian HL
    Microsoft Online Community Support


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.



    Thursday, December 13, 2012 6:02 AM
  • The purpose of System.ValueType is to override the virtual methods defined by System.Object. So when the runtime encounters a type derived from System.ValueType, then stack allocation is achieved.Hence No overhead of removing an object from memory.

    Check out this

    http://forums.asp.net/t/1618448.aspx/1



    • Edited by Manjula.C Thursday, December 13, 2012 1:10 PM
    Thursday, December 13, 2012 1:07 PM