Error while debugging list

I have a list which contains 2 variables:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SlowOrder //holds the values for slows
{
	public float Speed;
	public float Duration;
	
	public SlowOrder(float speed, float duration)
	{
		Speed = speed;
		Duration = duration;
	}
}

public class UnityTest : MonoBehaviour 
{
	public List<SlowOrder> slowOrder = new List<SlowOrder>();

	public float walking;
	public float currentSlowDuration;

	void SlowEffect(List<float> slowHolder) //sendmessage from projectiles //list [0] = percent [1] = duration
	{
		float wTemp = walking - (walking * slowHolder [0]); //new slowed walking speed
		float dTemp = currentSlowDuration - Time.time; //current slowed duration, left

            slowOrder.Add (new SlowOrder (wTemp, slowHolder[1] + Time.time));

		for(int i = 0; i < slowOrder.Count; i++) //debugging
		{
			Debug.Log ("speed = " + slowOrder_.Speed + " / duration = " + slowOrder*.Duration);*_

* }*

* slowHolder.Clear (); //clears this methods list “SlowOrder” for next*
* }*
}
I get this Error:
ArgumentException: does not implement right interface
But only when I add to the list and then debugs. The first fire dose not give errors.
I used this type of list and not a dictionary cause i will have duplicate keys and values.
Still learning scripting, so be nice and simple.
James

If you want to sort a List the elements in the list must be comparable in some way. Common types like int, float, and strings are already comparable.
However if you define your own type you must also define a way to sort the elements, otherwise the Sort method won’t know what to do.

You have two options to define how you want to sort a new type.

Using IComparable
Make SlowOrder implements the interface IComparable which requires to define a method named CompareTo. This is basically what @Jessespike suggested. The interface is available on Unity, I’ve used it several times. If it gives you a compilation error then you must add using System; to the beginning of the file.

Using IComparer
The previous approach can be useful to define a default sorting for SlowOrder elements, the problem is that it only allows sorting in one specific way, and you might be interested in sorting a list in different ways. Maybe you want to sort by Speed, ascending or descending depending on the situation, or maybe you have one case where you want to sort SlowOrder elements by Duration, instead of Speed.

For this situation you can create new classes that implements IComparer. That interface only’s purpose is define a method with the algorithm to sort collections containing other types, so you can create several classes implementing IComparer where each class contains a different sorting algorithm:

using System.Collections.Generic;

public class SlowOrderSortByDuration : IComparer<SlowOrder>
{
     int Compare(SlowOrder x, SlowOrder y) 
     {
          return x.Duration < y.Duration;
      }
}

// Now sort the list using this comparer
slowHolder.Sort(new SlowOrderSortByDuration());

To avoid creating a new object each time that you want to sort a list, I recommend you to just add an static field of the IComparer to the class you want to sort:

public class SlowOrder //holds the values for slows
 {
     public class SortByDuration : IComparer<SlowOrder>
     {
         int Compare( SlowOrder x, SlowOrder y) 
         {
              return( x.Duration < y.Duration;
          }
     }
     static public SortByDuration  ByDuration = new SortByDuration();

     public float Speed;
     public float Duration;
     
     public SlowOrder(float speed, float duration)
     {
         Speed = speed;
         Duration = duration;
     }
 }

So now you can sort your list like this:

slowHolder.Sort(SlowOrder.ByDuration);

Now, if you want to sort SlowOrder elements in different ways, you only need to create another different class implementing IComparer and implementing the new sorting method, for example:

   slowHolder.Sort(SlowOrder.BySpeedDescending)