We are excited to announce that the ASP.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

LINQ - Minimum and Maximum range will not functioning proper..? [Answered] RSS

2 replies

Last post Aug 10, 2017 09:12 AM by gani7787

• gani7787

Member

209 Points

701 Posts

LINQ - Minimum and Maximum range will not functioning proper..?

Hi,

I'm checking minimum and maximum range using linq.

the below example code should return one value. but, it returns 0.

Min : 29.8

Max : 30.2

Finding value in dt table : 30.

code :

double MinNo = 30 - 0.2; //29.8
double MaxNo = 30 + 0.2; //30.2
DataTable dt = new DataTable();
dt.Columns.AddRange(new[] { new DataColumn("HEIGHT"), new DataColumn("WIDTH") });

var results = (from row in dt.AsEnumerable()

let MinSize = Convert.ToInt64(row.Field<string>("HEIGHT"))
let MaxSize = Convert.ToInt64(row.Field<string>("HEIGHT"))
where MinNo >= MinSize && MaxNo <= MaxSize

select new
{
PIPE_DIA = Convert.ToDouble(row.Field<string>("WIDTH")),
}).Count();

if (results > 0)
{

var results1 = (from row in dt.AsEnumerable()

let MinSize = Convert.ToInt64(row.Field<string>("HEIGHT"))
let MaxSize = Convert.ToInt64(row.Field<string>("HEIGHT"))
where MinNo >= MinSize && MaxNo <= MaxSize

select new
{
Results = Convert.ToDouble(row.Field<string>("WIDTH")),
}).Distinct();

foreach (var n1 in results1)
{
double Results = Double.Parse(n1.Results.ToString());
}
}

what is the problem..?

• Billy Liu

Contributor

2260 Points

815 Posts

Re: LINQ - Minimum and Maximum range will not functioning proper..?

Aug 10, 2017 07:34 AM|Billy Liu|LINK

Hi gani7787,

`where MinNo <= MinSize && MaxNo >= MaxSize`

Best Regards,

Billy

MSDN Community Support
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
• gani7787

Member

209 Points

701 Posts