Skip to content

Instantly share code, notes, and snippets.

@milovidov983
Created September 27, 2019 14:51
Show Gist options
  • Save milovidov983/6a56742743862fe3f78f39b814fb3729 to your computer and use it in GitHub Desktop.
Save milovidov983/6a56742743862fe3f78f39b814fb3729 to your computer and use it in GitHub Desktop.
When enums come from an unreliable source
using System.Linq;
using System;
enum MyEnum {
Item = 1
};
int[] myEnums = new[] { 1, 2, 3 };
MyEnum[] myEnum = myEnums.Where(x => Enum.IsDefined(typeof(MyEnum), x)).Select(x=>(MyEnum)x).ToArray();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment