If you want to return the elapsed time of the stopwatch you could do it like this
public IList BubbleSort(IList arrayToSort, out long elapsedTime)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
int n = arrayToSort.Count - 1;
for (int i = 0; i < n; i++)
{
for (int j = n; j > i; j--)
{
if (((IComparable)arrayToSort[j - 1]).CompareTo(arrayToSort[j]) > 0)
{
object temp = arrayToSort[j - 1];
arrayToSort[j - 1] = arrayToSort[j];
arrayToSort[j] = temp;
RedrawItem(j);
RedrawItem(j - 1);
RefreshPanel(pnlSamples);
}
Thread.Sleep(speed);
}
}
stopWatch.Stop();
elapsedTime = stopWatch.ElapsedMilliseconds;
return arrayToSort;
}
then you would call it something like this
long methodTime;
IList myList = BubbleSort(listToSort, out methodTime);
Hope this helps