Skip to content

Instantly share code, notes, and snippets.

@jakesays-old
Created March 1, 2016 22:44
Show Gist options
  • Select an option

  • Save jakesays-old/0d7b85f2a6b340d6befb to your computer and use it in GitHub Desktop.

Select an option

Save jakesays-old/0d7b85f2a6b340d6befb to your computer and use it in GitHub Desktop.
c# traits thing
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