Generic classes in C#
Forums:
class Size<T> {
public T Width { get; set; }
public T Height { get; set; }
public Size(T width, T height) {
Width = width;
Height = height;
}
public string AsText() {
return String.Format("[{0}; {1}]", Width, Height);
}
}
var sizeInt = new Size<int>(5, 8);
var textInt = sizeInt.AsText();
//textInt is "[5; 8]"
var sizeFloat = new Size<float>(3.7f, 1.58f);
var textFloat = sizeFloat.AsText();
//textFloat is "[3.7; 1.58]"
- Log in to post comments