Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

You can definitely use the collection initializer showed by @Paparazzi@Paparazzi

var processDetails = new List<OnGoingProcess>()
{ 
    new OnGoingProcess(120, "Process 29", "T20"), 
    new OnGoingProcess(85, "Process 229")
};

Like others I have difficulties to understand the requirements but I think what you are looking for is a Union

Produces the set union of two sequences by using a specified IEqualityComparer.

With it you can replace the entire foreach as

var mergedProcesses = processDetails.Union(routePlans, new ProcessEqualityComparer());

where

class ProcessEqualityComparer : IEqualityComparer<OnGoingProcess>
{
    public bool Equals(OnGoingProcess left, OnGoingProcess right) 
    {
        return left.Id == right.Id;
    }

    public int GetHashCode(OnGoingProcess process)
    {
        return process.Id.GetHashCode();
    }
}

The result is:

120 Process 29  T20
100 Process 2   A20
99  Process 3   S20
85  Process 229 B20
220 Process 39  C20
15  Process 20  D20
101 Process 129 G20
222 Process new null

You can definitely use the collection initializer showed by @Paparazzi

var processDetails = new List<OnGoingProcess>()
{ 
    new OnGoingProcess(120, "Process 29", "T20"), 
    new OnGoingProcess(85, "Process 229")
};

Like others I have difficulties to understand the requirements but I think what you are looking for is a Union

Produces the set union of two sequences by using a specified IEqualityComparer.

With it you can replace the entire foreach as

var mergedProcesses = processDetails.Union(routePlans, new ProcessEqualityComparer());

where

class ProcessEqualityComparer : IEqualityComparer<OnGoingProcess>
{
    public bool Equals(OnGoingProcess left, OnGoingProcess right) 
    {
        return left.Id == right.Id;
    }

    public int GetHashCode(OnGoingProcess process)
    {
        return process.Id.GetHashCode();
    }
}

The result is:

120 Process 29  T20
100 Process 2   A20
99  Process 3   S20
85  Process 229 B20
220 Process 39  C20
15  Process 20  D20
101 Process 129 G20
222 Process new null

You can definitely use the collection initializer showed by @Paparazzi

var processDetails = new List<OnGoingProcess>()
{ 
    new OnGoingProcess(120, "Process 29", "T20"), 
    new OnGoingProcess(85, "Process 229")
};

Like others I have difficulties to understand the requirements but I think what you are looking for is a Union

Produces the set union of two sequences by using a specified IEqualityComparer.

With it you can replace the entire foreach as

var mergedProcesses = processDetails.Union(routePlans, new ProcessEqualityComparer());

where

class ProcessEqualityComparer : IEqualityComparer<OnGoingProcess>
{
    public bool Equals(OnGoingProcess left, OnGoingProcess right) 
    {
        return left.Id == right.Id;
    }

    public int GetHashCode(OnGoingProcess process)
    {
        return process.Id.GetHashCode();
    }
}

The result is:

120 Process 29  T20
100 Process 2   A20
99  Process 3   S20
85  Process 229 B20
220 Process 39  C20
15  Process 20  D20
101 Process 129 G20
222 Process new null
edited body
Source Link
t3chb0t
  • 44.3k
  • 9
  • 84
  • 190

You can definitely use the collection initializer showed by @Paparazzi

var processDetails = new List<OnGoingProcess>()
{ 
    new OnGoingProcess(120, "Process 29", "T20"), 
    new OnGoingProcess(85, "Process 229")
};

Like others I have difficulties to understand the requirements but I think what you are looking for is a Union

Produces the set union of two sequences by using a specified IEqualityComparer.

With it you can replace the entire foreach as

var mergedProcesses = processDetails.Union(routePlans, new ProcessEqualityComparer());

where

class ProcessEqualityComparer : IEqualityComparer<OnGoingProcess>
{
    public bool Equals(OnGoingProcess left, OnGoingProcess right) 
    {
        return left.Id == right.Id;
    }

    public int GetHashCode(OnGoingProcess process)
    {
        return process.Id.GetHashCode();
    }
}

The result is:

99 120 Process 3 29  S20T20
220100 Process 392  C20 A20
1599  Process 203  D20
100 ProcessS20
85 2 Process 229 A20B20
120220 Process 2939  T20C20
22215  Process new20 null
85 D20
101 Process 229129 B20G20
101222 Process 129new G20null

You can definitely use the collection initializer showed by @Paparazzi

var processDetails = new List<OnGoingProcess>()
{ 
    new OnGoingProcess(120, "Process 29", "T20"), 
    new OnGoingProcess(85, "Process 229")
};

Like others I have difficulties to understand the requirements but I think what you are looking for is a Union

Produces the set union of two sequences by using a specified IEqualityComparer.

With it you can replace the entire foreach as

var mergedProcesses = processDetails.Union(routePlans, new ProcessEqualityComparer());

where

class ProcessEqualityComparer : IEqualityComparer<OnGoingProcess>
{
    public bool Equals(OnGoingProcess left, OnGoingProcess right) 
    {
        return left.Id == right.Id;
    }

    public int GetHashCode(OnGoingProcess process)
    {
        return process.Id.GetHashCode();
    }
}

The result is:

99  Process 3   S20
220 Process 39  C20
15  Process 20  D20
100 Process 2   A20
120 Process 29  T20
222 Process new null
85  Process 229 B20
101 Process 129 G20

You can definitely use the collection initializer showed by @Paparazzi

var processDetails = new List<OnGoingProcess>()
{ 
    new OnGoingProcess(120, "Process 29", "T20"), 
    new OnGoingProcess(85, "Process 229")
};

Like others I have difficulties to understand the requirements but I think what you are looking for is a Union

Produces the set union of two sequences by using a specified IEqualityComparer.

With it you can replace the entire foreach as

var mergedProcesses = processDetails.Union(routePlans, new ProcessEqualityComparer());

where

class ProcessEqualityComparer : IEqualityComparer<OnGoingProcess>
{
    public bool Equals(OnGoingProcess left, OnGoingProcess right) 
    {
        return left.Id == right.Id;
    }

    public int GetHashCode(OnGoingProcess process)
    {
        return process.Id.GetHashCode();
    }
}

The result is:

120 Process 29  T20
100 Process 2   A20
99  Process 3   S20
85  Process 229 B20
220 Process 39  C20
15  Process 20  D20
101 Process 129 G20
222 Process new null
Source Link
t3chb0t
  • 44.3k
  • 9
  • 84
  • 190

You can definitely use the collection initializer showed by @Paparazzi

var processDetails = new List<OnGoingProcess>()
{ 
    new OnGoingProcess(120, "Process 29", "T20"), 
    new OnGoingProcess(85, "Process 229")
};

Like others I have difficulties to understand the requirements but I think what you are looking for is a Union

Produces the set union of two sequences by using a specified IEqualityComparer.

With it you can replace the entire foreach as

var mergedProcesses = processDetails.Union(routePlans, new ProcessEqualityComparer());

where

class ProcessEqualityComparer : IEqualityComparer<OnGoingProcess>
{
    public bool Equals(OnGoingProcess left, OnGoingProcess right) 
    {
        return left.Id == right.Id;
    }

    public int GetHashCode(OnGoingProcess process)
    {
        return process.Id.GetHashCode();
    }
}

The result is:

99  Process 3   S20
220 Process 39  C20
15  Process 20  D20
100 Process 2   A20
120 Process 29  T20
222 Process new null
85  Process 229 B20
101 Process 129 G20