-1

I have created a class, which contain a string, byte array and a datetime variables.

also created a queue for for this class,

I want to sort the queue per the datetime which is inside the class

what is the best way to do that to compelte the method sortQueue?

 public class DataToPassOn
{
    public DateTime dt;
    public byte [] Data;
    public string  ComName;

    public DataToPassOn(int length)
    {
        dt = new DateTime ();
        Data = new byte[length];
        ComName="";
    }

}
 public class sorting
  {
      private Queue<DataToPassOn> _QdataToPassOn;

       public sorting ()
       {
          _QdataToPassOn = new Queue<DataToPassOn>();
       }

       public void sortQueue ()
       {
       }

   }
Barak Rosenfeld
  • 384
  • 5
  • 18

1 Answers1

1

You can use linq to sort your queue:

_QdataToPassOn = new Queue<DataToPassOn>(_QdataToPassOn.OrderBy(x => x.dt));
erikscandola
  • 2,442
  • 2
  • 14
  • 21
  • but how should I replace x? does I need to replace x with dt? – Barak Rosenfeld Jan 06 '16 at 08:59
  • Sorry, I fixed the code with `dt`. You don't need to replace x with dt, this is a [lambda expression](https://msdn.microsoft.com/en-us/library/bb397687.aspx). The x is like a temp variable with an object of type `DataToPassOn`. – erikscandola Jan 06 '16 at 09:03