Generic image class with generic data type in C# -
i create generic image class generic data type shown in code below.
in implementation thing not have declare class like: image<bgr<byte>, byte> a;
instead of:
image<bgr, byte> a;
is there way accomplish ?
public interface icolor<t> { } public struct bgr<t>: icolor<t> { public t b; public t g; public t r; } public class image<tcolor, t> tcolor: icolor<t> { tcolor[,] data; } class program { static void main(string[] args) { image<bgr<byte>, byte> a; } }
all i've done made icolor
non-generic, , followed through:
public interface icolor { } public struct bgr<t>: icolor { public t b; public t g; public t r; } public class image<tcolor> tcolor: icolor { tcolor[,] data; } class program { static void main(string[] args) { image<bgr<byte>> a; } }
the fact there different bgr
s depending on type t
needn't mean icolor
implementations have depend on type t
. there icolor
implementations zero, 2, or 9 type parameters - long meet actual contract of icolor
(which easy do...), ok.
Comments
Post a Comment