c# - LINQ Query Decimal Field to Constant Value -


i have stack of different colored pick-up sticks want remove duplicates , sort color , shortest longest in each color.

here's partial code:

stickstack stickstack = new stickstack(); list<stick> nodupesticks = stickstack.pile     .groupby(st => new { st.lengthincm, st.colorblue, st.colorgreen, st.colorred })     .select(st => st.firstordefault()).tolist(); var bluesticks = nodupesticks     .orderby(s => s.lengthincm)     .where(s => s.lengthincm >= 5.0m && s.lengthincm <= 20.0m && s.colorblue >= s.colorgreen && s.colorblue >= s.colorred)     .select(s => new stick(s.lengthincm, s.colorred, s.colorgreen, s.colorblue)); var greensticks = nodupesticks     .orderby(s => s.lengthincm)     .where(s => s.lengthincm >= 5.0m && s.lengthincm <= 20.0m && s.colorgreen >= s.colorblue && s.colorgreen >= s.colorred)     .select(s => new stick((decimal)s.lengthincm, s.colorred, s.colorgreen, s.colorblue)); sortbycolorresult result = new sortbycolorresult(); result.blues = bluesticks.tolist(); result.greens = greensticks.tolist(); 

instantiating stickstack creates list<stick> pile of sticks.

unfortunately, somewhere in this, lengthincm values (which should range 5.0m 20.0m) come out 5.

anybody have idea what's wrong here?

edit in response comments: here's stick class:

    public class stick {     public decimal lengthincm { get; private set; }     public int colorred { get; private set; }     public int colorgreen { get; private set; }     public int colorblue { get; private set; }      public stick(         decimal lengthincm,         int colorred,         int colorgreen,         int colorblue)     {         lengthincm = lengthincm;         colorred = colorred;         colorgreen = colorgreen;         colorblue = colorblue;     } } 

as can see, lengthincm decimal; rest of fields int. also, in comments asked why sorter routine explicitly cast length values decimal. 1 of many things tried make lengthincm appear decimal value other 5.

some sample sticks are:

        stick1 = new stick(10.00m, 256, 128, 50);         stick2 = new stick(10.00m, 256, 128, 50);         stick3 = new stick(20.00m, 128, 50, 256); 

as mentioned instantiating stickstack, creates pile (list) of somewhere between 2 million , 5 million records.

the lengthincm each record random decimal between 5.0 , 20.0.

hope helps.

edit: add pile creation code:

            (int = 0; < size; i++)         {             _pile.add(                 new straw(                     generator.next(length_min, length_max) / (decimal)10,                     generator.next(color_min, color_max),                     generator.next(color_min, color_max),                     generator.next(color_min, color_max)                 ));         } 

also, you'll know constants are:

    private const int pile_size_min = 2000000;     private const int pile_size_max = 3000000;     private const int color_min = 0;     private const int color_max = 256;     private const int length_min = 50;     private const int length_max = 200; 

and, because ask, here's output after first linq statement (list dupes removed). enter image description here

and more prove lengthincm change: enter image description here

finally, here's sample of blue stick list: enter image description here enter image description here

don't know else tell you. query creates nodupesticks has increasing decimal values lengthincm, query creates blue subset, returns 5 lengthincm.

thanks.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -