> Yes, but i was looking for a sytax to
> define the struct in such a way that the
> "warping" is "already there".
I don't really get the question. Is it a requirement that you use the
++ syntax? If so, then you can't do what you are asking, not without
special code like you and Gilles have posted. Enums in C# are really
little more than a wrapper around some integral type other than char, and
so they pretty much only do the things you could do with an integral type.
If you can use alternative syntax, I suppose one solution would be to
provide a mapping array:
Direction[] dirNext = { Two, Three, Four, Five, Six, Seven
Seven, Eight, Nine, Ten, Eleven, Twelve, One };
Then the next Direction is just:
Direction dirCur = Direction.One;
dirCur = dirNext[(int)dirCur];
(I'm sitting here wondering if extension methods word on enums...if so,
you could even make an extension method so that the code actually looked
something like: "dirCur = dirCur.Next()", putting the mapping array lookup
into the "Next()" extension method)
> Plus, i try to avoid modulo as plague due to
> performance resons.
Now _that_ I think isn't sensible. I doubt that modulo is all that
expensive anyway as compared to the conditional (it certainly has the
advantage of avoiding branching, so there's no branch-prediction to go
wrong), and even if it were, your code would have to be doing basically
_only_ modulo for that to be a concern.
Pete