Value types or reference types? Structures or classes? When should you use each? This is not C ++, in which you define all types as value types and can create references to them. This isnt Java, in which everything is a reference type (unless you are one of the language developers). You must decide how all instances of your type will behave when you create it. This is an important decision for the first time. You have to live with the consequences of your decision, because changing later can lead to code to break the subtle paths. this is a simple question about choosing a structure or a class keyword when creating a type, but its much more updated for all clients using your type if you change it later.
It is not as simple as preference on the other. The right choice depends on how you expect to use the new type. Value types are not polymorphic. They are better suited for storing data that your application is manipulating. Link types can be polymorphic and should be used to determine the behavior of your expression. Consider the expected responsibility of your new type and from these responsibilities, which type to create. Store data structures. Classes define behavior.
Suppose you read something fantastic and want a friend to read it too. Suppose further that his document is in the public domain, simply to avoid any allegations of supporting copyright infringement. What do you need to give your friend so that he can read it too? It depends entirely on what you read.
First, let's take a good look at the case when you have real paper in your hands. to give a friend a copy, you need to copy all the pages, and then give it to him. At this moment, he has his own full copy of the document. This situation dealt with value type behavior. All information is right at your fingertips - you do not need to go anywhere else to get it. Your copy information is also independent of your friends after you made a copy. You can add some notes to your pages, and its pages will not be changed at all.
Compare this to the situation when you read a web page. This time, all you need is to give your friend the URL of the web page. This is a link type behavior, with a URL replacing the link location. In order to really read the document, you need to follow the link placing the URL in your browser and asking him to load the page. On the other hand, when you change the web page for some reason (imagine your wiki and you added your notes to the page), you and your friend will see that the next time each of you loads the page.
The differences we saw in the real world is the heart of the difference between value types and reference types in C # and .NET. Most types in .NET are reference types and you are likely to create much more than value types. Most common cases that you should know are classes (declared using a class) are reference types and structures (using struct is declared) - value types. Other following situations:
Array types are reference types, even if the element type is a value type (therefore int [] is still a reference type, even if int is a value type).
Enumerations (declared using an enumeration) are value types.
Delegate types (declared using a delegate) are reference types.
Interface types (declared using an interface) are reference types, but they can be implemented by value types.
Now that we have a basic understanding of what reference types and value types are about, take a good look at some of the most important details.