Created
March 1, 2016 22:44
-
-
Save jakesays-old/0d7b85f2a6b340d6befb to your computer and use it in GitHub Desktop.
c# traits thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class ArrayTrait | |
| { | |
| public abstract int Dimensions { get; } | |
| } | |
| class TwoDimensionalArrayTrait : ArrayTrait | |
| { | |
| public override int Dimensions { get; } => 2; | |
| } | |
| class FixedArray<TElementType, TArrayTrait> | |
| where TArrayTrait : ArrayTrait, new() | |
| { | |
| private TElementType[] _elements; | |
| private static readonly TArrayTrait _traits = new TArrayTrait(); | |
| public FixedArray() | |
| { | |
| _elements = new TElementType[_traits.Dimensions * _traits.Dimensions]; | |
| } | |
| public TElementType At(params int[] indexes) | |
| { | |
| //... | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment