how to pass a function to a function

I have a function that differs in only one real way for various methods. How it sorts input. For example if you want the lowest 2 points on the face of a object it finds all objects in the face and sorts them by Y. If you want the farthest in an X or Z axis direction it sorts by that.

I would like to pass to the function the sort method to be passed to sort.

so like

int CompareY(int first, int second)
{
  ....
}

later i’ll use that method via

facevertices.sort(CompareY)

the thing is i’d like to be able to do something like

int mymethod(void sortmethod)
{
facevertices.sort(sortmethod)
}

and then be able to pass it compareY or compareZ or compareX as the sort method.

is that possible to pass a function itself?

While you could use a switch to handle the different methods of sorting this is actually a pretty good use case for playing with the Action and Func features of the C# language. Check this out!