title: Compare Enums of objects of the same enum type
body: <p>I've found similar questions to what I'm about to ask, but they unfortunately don't quite fit what I'm trying to do.</p>
  
  <p>I have multiple objects with an enum type called TypeOfEnum.</p>
  
  <pre><code>object A = TypeOfEnum.Value1,TypeOfEnum.Value2;
  object B = TypeOfEnum.Value2;
  object C = TypeOfEnum.Value3,TypeOfEnum.Value2;
  object D = TypeOfEnum.Value1,TypeOfEnum.Value4;
  </code></pre>
  
  <p>What I am attempting to do is compare the values of two of those four objects, and if they <em>contain</em> any of the same values (such as A and D, but not D and B) continue through the code. If they do not, the result is skipped and a new object comparison is . In the comparison, they will always have the same enum type, the object will always contain enums.</p>
  
  <p>I've thus far attempted to pass the enums to lists and check to see if they intersect at all as strings rather than ints, but it has had mixed results. IE: Object B and Object C will not match up, but Object A and C will, and Object D and A will.</p>
  
  <p>How can I do this? Or is it not possible?</p>
  
  <p>EDIT: 
  The actual code up to where the problem might be:
  Enums:</p>
  
  <pre><code>[Flags]
  public enum TerrainFlags
  {
      None = 0,
      Land = 1,
      Water = 2,
      Air = 4,
      Snow = 8,
      Desert = 16,
      Forest = 32,
      Mountain = 64
  }
  </code></pre>
  
  <p>Add Enemies to encounter:</p>
  
  <pre><code>private void AddEnemyAndUpdatePoints(List&lt;Enemy&gt; enemyList, Enemy enemy, ref int points, ref int bonusMoney, Village village)
      {
          List&lt;string&gt; terrainVillages = new List&lt;string&gt;();
          List&lt;string&gt; terrainEnemies = new List&lt;string&gt;();
          terrainVillages.Add(Enum.GetName(typeof(TerrainFlags), village.Terrain));
          foreach(string terrain in terrainVillages)
              Debug.Log("Village "+village.Name+" "+terrain);
          terrainEnemies.Add(Enum.GetName(typeof(TerrainFlags), enemy.Terrain));
          foreach (string terrain in terrainEnemies)
              Debug.Log("enemy: "+enemy.Name+" "+terrain);
          if (terrainVillages.Intersect(terrainEnemies).Any())
          {
              enemyList.Add(enemy);
              bonusMoney += enemy.Bounty;
              points -= enemy.Points;
              Debug.Log("Enemy Added");
          }
          else
          {
              Debug.Log("Enemy and Village Terrains did not match, rerolling.");
              points -= enemy.Points;
          }
  </code></pre>
  
  <p>Please note, the points -= enemy.Points in the else statement is simply to prevent an infinite loop this problem has caused and can otherwise be ignored.</p>
  
  <p>The AddEnemyAndUpdatePoints method is called in the following method:</p>
  
  <pre><code>private int BuyPoints(List&lt;Enemy&gt; enemyList, int points, int difficulty, Village village)
      {
          int bonusMoney = 0;
          while (points &gt; 0)
          {
              var enemy = this.GetEnemyWeighted(EnemyListFunction());
              if (difficulty &lt;= 2 &amp;&amp; enemy.Points &lt;= 2)
              {
                  AddEnemyAndUpdatePoints(enemyList, enemy, ref points, ref bonusMoney, village);
              }
              else if (difficulty &gt; 2)
              {
                  AddEnemyAndUpdatePoints(enemyList, enemy, ref points, ref bonusMoney, village);
              }
          }
       return bonusMoney;
      }
  </code></pre>
  
  <p>More or less, the problem I seem to be having is if an enemy has the terrains of mountain, snow, and Air, the current code means they don't get paired with something if it has mountain only. It needs at least snow and mountain, or mountain and air, and will sometimes end up with enemies that are only desert and forest.</p>