C# can a class be aliased (not with 'using') -
in delphi, following possible:
class alias = dictionary<long, object>;
alias dictionary<long, object>
.
is possible in c#? i've never figured out how without having wrap dictionary custom class.
the using directive won't work since it's local file appears in.
not exactly.
but can this:
public class alias : dictionary<long, object> { }
this means can use alias
everywhere instance of dictionary<long, object>
required. can't use dictionary<long, object>
alias
required.
however, create implicit operator transparently convert dictionary<long, object>
alias
instance:
public class alias : dictionary<long, object> { public alias() {} public alias(dictionary<long, object> dictionary) { foreach(var kvp in dictionary) add(kvp); } public static implicit operator alias (dictionary<long, object> dictionary) { return new alias(dictionary); } }
please note implicit conversion operator create copy of dictionary might unexpected or undesired.
Comments
Post a Comment