Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there UI-independent Point struct in .NET?

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.

like image 421
Aleksey Shubin Avatar asked Feb 03 '14 15:02

Aleksey Shubin


People also ask

Where is struct used in C#?

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.

Does C# have structs?

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.

Can we create instance of struct in C#?

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.

Can we inherit struct C#?

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.


2 Answers

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.

like image 104
Crono Avatar answered Sep 20 '22 15:09

Crono


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.

like image 32
pid Avatar answered Sep 19 '22 15:09

pid