algorithm - List Occurence wise read c# -


i have class this

  public  class roomdetails   {      public int roomindexid {get;set;} --(this no of rooms)      public int roomcategoryid {get;set;} -- (this no of category room have)      public decimal roomprice{get;set;}      public string roomcategory{get;set;}   } 

so have roomdetails list this(data)

  • 1,1,200,single bed
  • 2,1,250,double bed
  • 2,2,400,double bed view
  • 2,4,530,tripple bed
  • 3,1,530,tripple bed
  • 3,2,600,triple large bed

so want read list following procedure.

  • 1,1,200,single bed
  • 2,1,250,double bed
  • 3,1,530,tripple bed

  • 1,1,200,single bed
  • 2,1,250,double bed
  • 3,2,600,triple large bed

  • 1,1,200,single bed
  • 2,2,400,double bed view
  • 3,1,530,tripple bed

  • 1,1,200,single bed
  • 2,2,400,double bed view
  • 3,2,600,triple large bed

  • 1,1,200,single bed
  • 2,4,530,tripple bed
  • 3,1,530,tripple bed

  • 1,1,200,single bed
  • 2,4,530,tripple bed
  • 3,2,600,triple large bed

please ask if have problem regrading question.

this example

my data list this

  • room -- a1
  • room b -- b1 , b2 , b3
  • room c -- c1 , c2

(actually ,b, c means roomindexid 's , a1,b1,b2,b3,c1,c2 roomcategoryid 's) want read this.

  • a1,b1,c1
  • a1,b1,c2
  • a1,b2,c1
  • a1,b2,c2
  • a1,b3,c1
  • a1,b3,c2

if want "linqy" solution, little complicated. please note linq object, need call .tolist() first if have iqueryable (for example entityframework).

var total = list.groupby(x=>x.roomindexid)     .select(x=>x.count())     .aggregate(1, (s,d)=>s*d);  var counts = list.groupby(x => x.roomindexid)     .todictionary(x => x.key, x => x.count());  var nums = list.groupby(x => x.roomindexid)     .select(x => x.select((p, i) => new {i, p}))     .selectmany(x => x)     .tolist();  var result = enumerable.range(0, total)     .select(x =>         nums.where(y => {                            var c = counts[y.p.roomindexid];             var p = counts                       .where(z => z.key > y.p.roomindexid)                       .aggregate(1, (s,d)=>s*d.value);              return y.i == x/p%c;         })         .select(y => y.p)     ); 

demo here: https://dotnetfiddle.net/udf6va


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -