I know several Point
structs in .NET: System.Drawing.Point
, System.Windows.Point
, Sys.UI.Point
, but all of them are in high-level UI libraries (GDI+, WPF, AJAX). I need a Point
struct for calculations in my class library which I don't want to tie to any specific UI technology. Is there any UI-independent Point
struct in .NET? Or I will need to create it myself? That is simple, I know, but sounds like reinventing the wheel.
The struct (structure) is like a class in C# that is used to store data. However, unlike classes, a struct is a value type. Suppose we want to store the name and age of a person. We can create two variables: name and age and store value.
C# - Struct. In C#, struct is the value type data type that represents data structures. It can contain a parameterized constructor, static constructor, constants, fields, methods, properties, indexers, operators, events, and nested types.
Unlike classes, structs can be instantiated without using the New operator. If the New operator is not used, the fields remain unassigned and the object cannot be used until all the fields are initialized.
A structure type can't inherit from other class or structure type and it can't be the base of a class. However, a structure type can implement interfaces.
To the best of my knowledge there isn't, but as you stated it isn't something hard to implement yourself so I suggest you do that.
You may be tempted to use Tuple
class as others suggested. While it can do the job it isn't something you'll want to reuse over and over. Furthermore you may run into comparison issues, depending on your app specifics.
Reinvent the wheel. It will run smoother! Really, if it's just a tiny struct why depend on big assemblies, pulling in a lot of other stuff? Especially on constraint devices like phones... But pay attention on how to use classes and struct correctly if you want best performance.
This is a pretty good read and I sense that you want to read it dearly: Frank Savage on CLR performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With