using System;
using System.Collections.Generic;
//This is my class for obtaining certain values, putting them in a List<T>
//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<MyValues> SRvalues = new List<MyValues>();
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<MyValues>
{
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.
}
をして一覧
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))...
すなわちメインクラスでそれらのいずれかをチェックすることができますが、私はそれが私がチェックしていますということです何のパラメータを区別するように、Equalsメソッドをコードに取り掛かるするかどうかはわかりません。どんな助けも高く評価されます。