0

Can I say that structs are new data types?

6th Jul 2017, 4:02 PM
Alyson Jorge
Alyson Jorge - avatar
2 Respostas
+ 1
Yes. A struct is custom datatype.
6th Jul 2017, 8:35 PM
sneeze
sneeze - avatar
+ 2
I suppose you can say anything you wish to say. "A struct type is a value type that is typically used to encapsulate small groups of related variables, such as the coordinates of a rectangle or the characteristics of an item in an inventory. Structs share most of the same syntax as classes, but are more limited than classes. Unlike classes, structs can be instantiated without using a new operator. Structs do not support inheritance and cannot contain virtual methods. Structs can contain methods, properties, indexers, and so on. Structs cannot contain default constructors (a constructor without parameters), but they can have constructors that take parameters. In that case the new keyword is used to instantiate a struct object, similar to class objects. Structs vs Classes In general, classes are used to model more complex behavior, or data, that is intended to be modified after a class object is created. Structs are best suited for small data structures that contain primarily data that is not intended to be modified after the struct is created. Consider defining a struct instead of a class if you are trying to represent a simple set of data. All standard C# types (int, double, bool, char, etc.) are actually structs."
6th Jul 2017, 4:06 PM
AgentSmith