I have one interface for device but the two classes I have using the interface also include a list of a class. The classes the list are using are of `ICommand`. This gives me a problem because I run into multiple of essentially the same methods as seen below with the average methods. I'm fairly new to C# so I'm wondering if there is some way I can use an abstract class or something to eliminate all this duplicate code. 

```
public interface IDevice
{
    double AvgCmdsMin { get; set; }
    double AvgTime { get; set; }
    string DeviceName { get; set; }
    double Duration { get; set; }
    int FailedCmds { get; set; }
    double MaxTime { get; set; }
    double MinTime { get; set; }
}

public class MuxDevice : IDevice
{
    public string DeviceName { get; set; } /*Name of Device*/
    public bool Active = false; /*True if device is currently waiting for a command response, false if not*/
    public List<MuxCmd> UsedCommands = new List<MuxCmd>(); /*List of all commands used by device*/
    public double MaxTime { get; set; } /*the longest time it took to receive a command response*/
    public double MinTime { get; set; } /*the shortest time it took to receive a command response*/
    public double AvgTime { get; set; } /*The average between all times to receive to a response*/
    public double Duration { get; set; } /*Total duration of all commands on device*/
    public double AvgCmdsMin { get; set; } /*How many commands were sent in a minute*/
    public int FailedCmds { get; set; } /*Number of commands that received an error*/
}

public class Device : IDevice
{
    public string DeviceName { get; set; } /*Name of Device*/
    public bool Active = false; /*True if device is currently waiting for a command response, false if not*/
    public List<Command> UsedCommands = new List<Command>(); /*List of all commands used by device*/
    public double MaxTime { get; set; } /*the longest time it took to receive a command response*/
    public double MinTime { get; set; } /*the shortest time it took to receive a command response*/
    public double AvgTime { get; set; } /*The average between all times to receive to a response*/
    public double Duration { get; set; } /*Total duration of all commands on device*/
    public double AvgCmdsMin { get; set; } /*How many commands were sent in a minute*/
    public int FailedCmds { get; set; } /*Number of commands that received an error*/
}

public interface ICommand
{
    string CmdType { get; set; }
    DateTime EndTime { get; set; }
    TimeSpan Length { get; set; }
    int RespBytes { get; set; }
    int RespCmd { get; set; }
    int SendBytes { get; set; }
    int SendCmd { get; set; }
    DateTime SendTime { get; set; }
}

private void AverageTime(List<Device> deviceStats)
{
    foreach (Device t in deviceStats)
    {
        long totalTicks = 0; /*total number of ticks(10,000 ticks in a millisecond)*/

        foreach (Command t1 in t.UsedCommands)
        {
            totalTicks += t1.Length.Ticks; /*adds up command lengths as ticks*/
        }

        TimeSpan totalDuration = new TimeSpan(totalTicks);
        t.Duration = totalDuration.TotalSeconds;

        if ((t.UsedCommands.Count - t.FailedCmds) == 0) /*if 0 commands*/
        {
            t.AvgTime = 0; /*Add avgTimeSpan to Device in seconds*/
        }
        else
        {
            var avgticks = totalTicks / (t.UsedCommands.Count - t.FailedCmds); /*Average ticks*/
            var avgTimeSpan = new TimeSpan(avgticks); /*Convert totalTicks to Timespan*/
            t.AvgTime = avgTimeSpan.TotalSeconds; /*Add avgTimeSpan to Device in seconds*/
        }
    }
}

private void MuxAverageTime(List<MuxDevice> deviceStats)
{
    foreach (MuxDevice t in deviceStats)
    {
        long totalTicks = 0; /*total number of ticks(10,000 ticks in a millisecond)*/

        foreach (MuxCmd t1 in t.UsedCommands)
        {
            totalTicks += t1.Length.Ticks; /*adds up command lengths as ticks*/
        }

        TimeSpan totalDuration = new TimeSpan(totalTicks);
        t.Duration = totalDuration.TotalSeconds;

        if ((t.UsedCommands.Count - t.FailedCmds) == 0) /*if 0 commands*/
        {
            t.AvgTime = 0; /*Add avgTimeSpan to Device in seconds*/
        }
        else
        {
            var avgticks =
                totalTicks / (t.UsedCommands.Count - t.FailedCmds); /*Average ticks*/
            var avgTimeSpan = new TimeSpan(avgticks); /*Convert totalTicks to Timespan*/
            t.AvgTime = avgTimeSpan.TotalSeconds; /*Add avgTimeSpan to Device in seconds*/
        }
    }
}

```