In C++, to sort a vector, a list or any collection, I would use:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main() {
vector<int> vt;
vt.push_back( 3 );
vt.push_back( 1 );
vt.push_back( 2 );
sort( vt.begin(), vt.end(), greater<int>() );
}
In C#, I found that List<>
is equivalent to std::vector<>
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Professional_Csharp {
class Program {
static void Main( string[] args ) {
List<int> intList = new List<int>();
intList.Add( 3 );
intList.Add( 2 );
intList.Add( 1 );
intList.Sort();
}
}
}
This worked fine, however if I want to customize the comparator, how could I implement that? Or if I want to sort just a specific range instead of the whole list? How could I do that?
Update
sort( vt.begin(), vt.begin() + 1 );
Is it possible in C#?
Thanks,
Chan