c# - Create a custom user collection of collections -
i need create generic collection of generic collections, should contain generic class. i've tried hard, haven't found answers.this how realizated collection looks like: https://github.com/infatum/pmc-data-model/blob/master/wtf/position.cs collection of position of generic class point. need create indexed collection of positions called matrix, indexed collection of matrix called container , indexed collection of containers, named containers. please, me!
public class matrix<t> : icollection<t> t : position<t> { protected arraylist matrix; protected bool isreadonly; public matrix() { matrix = new arraylist(); } // ... }
the trouble : type 't' cannot used type parameter 't' in generic type or method 'position'. there no implicit reference conversion 't' 'wtf.point'
this task, given me: https://docs.google.com/document/d/1zyxxajrh0oynluufy0ht6zuazisiece73cga4qordlc/edit#heading=h.nwbuqfwpq3gk
your type constraint on t
recursive - don't think want be. (and neither compiler: constraint enforces t
sort of position<t>
. means position<t>
position<position<t>>
- violates type constraint on generic argument of position
, expects wtf.point
instead of position
)
solution:
public class matrix<t> : icollection<position<t>>
but let me elaborate little more: in sense, want like
public class matrix<t> : icollection<t> t : position<u>
so there no more recursion. want t
"some kind of position
". have new problem: u
(let's call "element-type") come from? should use that generic type argument of matrix
:
public class matrix<u> : icollection<t> t : position<u>
now, constraint can collapsed directly interface type, i.e. icollection<position<u>>
giving solution gave above (modulo names).
Comments
Post a Comment