c# - Extend Dictionary and create instance from other dictionary -
i extending c# dictionary class:
class table<ta> : dictionary<int, ta> {}
but have dictionary, , want create table out of it. tried:
dictionary<int, int> mydico = ... // somewhere else table<int> mytable = new table{ mydico };
but complains with,
"table not contain constructor accepting argument."
i come java/scala background , because c# not have type aliases, way found utilize aliases.
just create constructor accepts dictionary, , pass base of operations constructor:
class table<ta> : dictionary<int, ta> { public table(idictionary<int, ta> dictionary) : base(dictionary) { } }
use this:
dictionary<int, int> mydico = ... // somewhere else table<int> mytable = new table(mydico);
c# dictionary
No comments:
Post a Comment