title: JAVA to C# conversion - PriorityQueue
body: <p>This question was posted here (<a href="https://stackoverflow.com/questions/15881110/java-to-c-sharp-conversion">https://stackoverflow.com/questions/15881110/java-to-c-sharp-conversion</a>) by a team member but was closed due to the community not having enough information. </p>
  
  <p>Here's my attempt to revive such a question being, <strong>How would I go about converting this java extract into C#?</strong></p>
  
  <p>Java Extract:</p>
  
  <pre><code>PriorityQueue&lt;PuzzleNode&gt; openList = new PriorityQueue&lt;PuzzleNode&gt;
             (1,
              new Comparator&lt;PuzzleNode&gt;(){
                  public int compare(PuzzleNode a, PuzzleNode b){
                      if (a.getPathCost() &gt; b.getPathCost())
                          return 1;
                      else if (a.getPathCost() &lt; b.getPathCost())
                          return -1;
                      else
                          return 0;
                      }
                  }
              );
  </code></pre>
  
  <p>A sortedList has been thought about but to no avail as I'm unsure how to code it.</p>
  
  <p>I've also tried creating a standard list with a method:</p>
  
  <pre><code>List&lt;PuzzleNode&gt; openList = new List&lt;PuzzleNode&gt;();
  
  //Method to sort the list
  public int CompareFCost(PuzzleNode a, PuzzleNode b)
          {
              if (a.getPathCost() &gt; b.getPathCost())
              {
                  return 1;
              }
              else if (a.getPathCost() &gt; b.getPathCost())
              {
                  return -1;
              }
              else
                  return 0;
          }//end CompareFCost
  </code></pre>
  
  <p>and then calling: openList.Sort(CompareFCost); at appropriate locations, however this doesn't work.</p>
  
  <p><strong>What the code is used for?</strong>
  It orders the objects 'PuzzleNode' depending on a score (pathCost) I have set else where in the program. A while loop then operates and pulls the first object from the list. The list needs to be ordered otherwise an object with a higher pathCost could be chosen and the while loop will run for longer. The objective is to pull the lower pathCost from the list. </p>
  
  <p>I ask for a conversion because it works in Java &amp; the rest of the code has pretty much originated from Java.</p>
  
  <p>Any takers? If you need further info I'm happy to discuss it further.</p>