<p>The <a href="http://msdn.microsoft.com/en-us/library/y23b5415.aspx" rel="nofollow noreferrer">official guidelines</a> suggest that there can be very few practical uses for these.  Does anyone have examples of where they've put them to good use?</p>

[{'answer_id': 37935, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 0, 'selected': False, 'text': '<p>Enums are first class citizens of .NET world. As for structures I found that in most cases classes can be used, however for memory-intense scenarios consider using structures. As a practical example I used structures as data structures for OSCAR (ICQ) protocols primitives.</p>\n'}, {'answer_id': 37938, 'author': 'Chris James', 'author_id': 3193, 'author_profile': 'https://Stackoverflow.com/users/3193', 'pm_score': 0, 'selected': False, 'text': '<p>I tend to use enum for avoiding magic numbers, this can be overcome by const I guess, but enum allows you to group them up.</p>\n\n<p>i.e</p>\n\n<pre><code>enum MyWeirdType {\nTypeA, TypeB, TypeC};\n\nswitch(value){\ncase MyWeirdType.TypeA:\n...\n</code></pre>\n'}, {'answer_id': 37967, 'author': 'Gishu', 'author_id': 1695, 'author_profile': 'https://Stackoverflow.com/users/1695', 'pm_score': 1, 'selected': False, 'text': "<p>Au Contrare... you'll find C/C++ people flocking to structs a.k.a. value types.<br>\nAn example would be data packets. If you have a large number of data packets to transfer/transmit, you'd use value structs to model your data packets.<br>\nreason: Turning something into a class adds an overhead of (approx 8-16 Bytes I forget) of <strong>overhead in the object header</strong> in addition to the instance data. In scenarios where this is unacceptable, value types are your safest bet<br>\nAnother use would be situations where you need <strong>value type semantics</strong> - once you create-initialize a object, it is readonly/immutable and can be passed around to n clients.</p>\n"}, {'answer_id': 37968, 'author': 'Jorge Córdoba', 'author_id': 2695, 'author_profile': 'https://Stackoverflow.com/users/2695', 'pm_score': 0, 'selected': False, 'text': '<p>You should use a value type whenever:</p>\n\n<ul>\n<li>The use of a class isn\'t necessary (no need for inheritance)</li>\n<li>You want to make sure there\'s no need to initialize the type.</li>\n<li>You have a reason to want the type to be allocated in stack space</li>\n<li>You want the type to be a complete independent entity on assigment instead of a "link" to the instance as it is in reference types.</li>\n</ul>\n'}, {'answer_id': 37970, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 0, 'selected': False, 'text': '<p>Exactly what most other people use them for.. Fast and light data/value access. As well as being ideal for making grouping properties (where it makes sense of course) into an object.</p>\n\n<p>For example:</p>\n\n<ul>\n<li>Display/Data value differences, such as String pairs of image names and a path for a control (or whatever). You want the path for the work under the hood, but the name to be visible to the user.</li>\n<li>Obvious grouping of values for the metrics of objects. We all know Size etc but there may be plenty of situations where the base "metric" types are not enough for you.</li>\n<li>"Typing" of enum values, being more than a fixed enum, but less that a full blown class (already has been mentioned, just want to advocate).</li>\n</ul>\n\n<p>Its important to remember the <a href="http://www.gafvert.info/CSharpDataTypes.htm" rel="nofollow noreferrer">differences between value and reference types</a>. Used properly, they can really improve efficiency of your code as well as make the object model more robust.</p>\n'}, {'answer_id': 37972, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 0, 'selected': False, 'text': "<p>Value types, specifically, structs and enums, and have proper uses in object-oriented programming.</p>\n\n<p>Enums are, as aku said, first class citizens in .NET, which can be used from all sorts of things from Colors to DialogBox options to various types of flags.</p>\n\n<p>Structs, as far as my experience goes, are great as Data Transfer Objects; logicless containers of data especially when they comprise mostly of primitive types.</p>\n\n<p>And of course, primitive types are all value types, which resolve to System.Object (unlike in Java where primitive types aren't related to structs and need some sort of wrapper).</p>\n"}, {'answer_id': 37978, 'author': 'ljs', 'author_id': 3394, 'author_profile': 'https://Stackoverflow.com/users/3394', 'pm_score': 0, 'selected': False, 'text': '<p>Actually prior to .net 3.5 SP1 there has been a performance issue with the intensive use of value types as mentioned here in <a href="http://blogs.msdn.com/vancem/archive/2008/05/12/what-s-coming-in-net-runtime-performance-in-version-v3-5-sp1.aspx" rel="nofollow noreferrer">Vance Morrison\'s blog</a>.</p>\n\n<p>As far as I can see the vast majority of the time you should be using classes and the JITter should guarantee a good level of performance.</p>\n\n<p>structs have \'value type semantics\', so will pass by value rather than by reference. We can see this difference in behaviour in the following example:-</p>\n\n<pre><code>using System;\n\nnamespace StructClassTest {\n\n  struct A {\n    public string Foobar { get; set; }\n  }\n\n  class B {\n    public string Foobar { get; set; }\n  }\n\n  class Program {\n    static void Main() {\n      A a = new A();\n      a.Foobar = "hi";\n      B b = new B();\n      b.Foobar = "hi";\n\n      StructTest(a);\n      ClassTest(b);\n\n      Console.WriteLine("a.Foobar={0}, b.Foobar={1}", a.Foobar, b.Foobar);\n\n      Console.ReadKey(true);\n    }\n\n    static void StructTest(A a) {\n      a.Foobar = "hello";\n    }\n\n    static void ClassTest(B b) {\n      b.Foobar = "hello";\n    }\n  }\n}\n</code></pre>\n\n<p>The struct will be passed by value so StructTest() will get it\'s own A struct and when it changes a.Foobar will change the Foobar of its new type. ClassTest() will receive a reference to b and thus the .Foobar property of b will be changed. Thus we\'d obtain the following output:-</p>\n\n<pre><code>a.Foobar=hi, b.Foobar=hello\n</code></pre>\n\n<p>So if you desire value type semantics then that would be another reason to declare something as a struct. Note interestingly that the DateTime type in .net is a value type, so the .net architects decided that it was appropriate to assign it as such, it\'d be interesting to determine why they did that :-)</p>\n'}, {'answer_id': 37981, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 1, 'selected': False, 'text': "<p>For the most part, it's good to emulate the behaviour of the framework. Many elementary data types such as <code>int</code>s are value types. If you have types that have similar properties, use value types. For example, when writing a <code>Complex</code> data type or a <code>BigInteger</code>, value types are the logical solution. The same goes for the other cases where the framework used value types: <code>DateTime</code>, <code>Point</code>, etc.</p>\n\n<p>When in doubt, use a reference type instead.</p>\n"}]
['https://Stackoverflow.com/questions/37931', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3974/']