How to override in IEquatable so as to use Contain and Exists methods in a List<T> with different types
07:57 28 Sep 2016
using System;
using System.Collections.Generic;

//This is my class for obtaining certain values, putting them in a List
//and then use the List to do certain operations 
public class SRvaluesChecker
{   
    double currentPriceValue;
    int totalVal, bullVal , bearVal , lineVal;

    //The List is of a custom object type
    List SRvalues = new List();

    for(int a = 0; a <= 1000; a++)
    {
        //Values are assigned to currentValue, totalVal, 
        //bullVal , bearVal and lineVal

    }

    //Check if the List has a particular value
    if(SRvalues.Exists(x => x.SRprice == currentPriceValue) == false)
    {
        //Do something
    }
}

//Here is the object I created so that I can store information of different
//data types in the list
public class MyValues : IEquatable
{   
    public override string ToString()
    {
        return "SRprice: " + SRprice + "   total count: " + totalCount + 
        "   bullish count: " + bullishCount + "   bearish count: " + bearishCount + 
        "   line type: " + lineType;
    }

    public MyValues(double SRprice, int totalCount, int bullishCount , int bearishCount, int lineType)
    {
        this.SRprice = SRprice;
        this.totalCount = totalCount;
        this.bullishCount = bullishCount;
        this.bearishCount = bearishCount;
        this.lineType = lineType;
    }

    public double SRprice { get; set; }
    public int totalCount { get; set; }
    public int bullishCount { get; set; }
    public int bearishCount { get; set; }
    public int lineType { get; set; } 

    public override bool Equals(object obj)
    {
        if (obj == null) return false;
        MyValues objAsPart = obj as MyValues;
        if (objAsPart == null) return false;
        else return Equals(objAsPart);
    }       

    //This currently only checks for one parameter (SRprice) but
    //I want to code for the others as well
    public bool Equals(MyValues other)
    {
        if (other == null) return false;
        return (this.SRprice.Equals(other.SRprice));
    }

    //Will override GetHashCode() and == and != operators later.        
}

As you can see from the code above, I have a custom object with 5 parameters and I want to be able to check for any one of them in the main class i.e.

if(SRvalues.Exists(x => x.SRprice == currentPriceValue))...
if(SRvalues.Exists(x => x.totalCount == totalVal))...
if(SRvalues.Exists(x => x.bullishCount == bullVal))...
if(SRvalues.Exists(x => x.bearishCount == bearVal))...
if(SRvalues.Exists(x => x.lineType == lineVal))...

but I am not sure how to go about coding for the Equals method so as to distinguish what parameter it is that I am checking for. Any help would be highly appreciated.

c# list equality exists iequatable