我有以下系列
我想查看用户输入号码(手机号码)是否属于该系列之一。
public class MobilePhoneSeries
{
public long SeriesStart { get; set; }
public long SeriesEnd { get; set; }
private IEnumerable<MobilePhoneSeries> DummyGetMobilePhoneSeries()
{
IList<MobilePhoneSeries> dummDtos = new List<MobilePhoneSeries>()
{
new MobilePhoneSeries(){SeriesStart = 40000000, SeriesEnd =49999999 },
new MobilePhoneSeries(){SeriesStart = 46700000000, SeriesEnd = 46799999999 },
new MobilePhoneSeries(){SeriesStart = 90000000, SeriesEnd = 99999999 }
};
return dummDtos;
}
private bool MobilePhoneSeriesValidation(string num)
{
var res = DummyGetMobilePhoneSeries();
//??????????????????
}
}
答案 0 :(得分:2)
您可以使用Enumerable.Any,最好将长传递给方法MobilePhoneSeriesValidation
,而不是传递string
。因为您必须将其与long
进行比较。
private bool MobilePhoneSeriesValidation(string num)
{
long numLong = long.Parse(num);
var res = DummyGetMobilePhoneSeries();
return res.Any(c=> c.SeriesStart <=numLong && c.SeriesEnd >= numLong );
}
如果您将long
传递给MobilePhoneSeriesValidation
而不是字符串。
private bool MobilePhoneSeriesValidation(long num)
{
var res = DummyGetMobilePhoneSeries();
return res.Any(c=> c.SeriesStart <=numLong && c.SeriesEnd >= numLong );
}