Skip to content

Instantly share code, notes, and snippets.

@j0inty
Last active October 7, 2016 17:52
Show Gist options
  • Save j0inty/5f13dd92a3b106401e52f5913067a96b to your computer and use it in GitHub Desktop.
Save j0inty/5f13dd92a3b106401e52f5913067a96b to your computer and use it in GitHub Desktop.
// Remember: This is a very simple example. enum's with gaps will not work as expected ...
enum JobStatsIdx
{
None = 0,
First = 1,
Second = 2,
Third = First | Second,
Eight = 8,
Nine = 9
};
// Array initialization Without LINQ
int[] jobStatsIdxStartValues = Array.ConvertAll(new int[Enum.GetNames(typeof(JobStatsIdx)).Length], v => 0);
// With LINQ
Enumerable.Repeat(0, Enum.GetNames(typeof(JobStatsIdx)).Length).ToArray()
Result:
Array[0] = 0;
Array[1] = 0;
Array[2] = 0;
Array[3] = 0;
Array[4] = 0; // wrong Must be index 8
Array[5] = 0; // wrong Must be index 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment