Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#, quick generics question

Tags:

c#

I have a need to create a quick class with just 2 properties (left and top), I'll then call these in a collection.

Is there a quick way to create the class structure without having to actually create the strongly typed class itself using generics?

Thanks in advance

Better still, does the framwework have a built in type than can just store left, top, right, bottom co-ordinates in integer values?

like image 815
JL. Avatar asked Dec 02 '22 06:12

JL.


2 Answers

Automatic Properties would help make this quick

public class Position<T> where T: struct
{
  public T Top { get; set; }
  public T Left { get; set; }
}

Or you might want to check out the Point or Rectangle classes in the System.Drawing namespace.

like image 118
NerdFury Avatar answered Dec 03 '22 22:12

NerdFury


I think you're looking for System.Drawing.Rectangle (which is a struct, not a class by the way; there's a class in System.Windows.Shapes but that's different.) There's no point in creating a new generic type when what you want is already in the framework.

like image 29
Jon Skeet Avatar answered Dec 03 '22 22:12

Jon Skeet