[{"data":1,"prerenderedAt":880},["ShallowReactive",2],{"article-generic-collections-and-filtering":3},{"article":4,"tags":775,"previous":790,"next":832},{"id":5,"title":6,"author":7,"body":8,"createdAt":765,"description":14,"extension":766,"img":759,"meta":767,"navigation":768,"path":769,"seo":770,"stem":771,"tags":772,"updatedAt":765,"__hash__":774},"articles\u002Farticles\u002Fgeneric-collections-and-filtering.md","Generic Collections and Filtering","[object Object]",{"type":9,"value":10,"toc":762},"minimark",[11,15,18,21,24,27,404,753,756],[12,13,14],"p",{},"When dealing with collections the common question is how to filter them based on criteria. ",[12,16,17],{},"The following are a few techniques used to accomplish this.  A delegate is like a function pointer. ",[12,19,20],{},"A predicate is a method that returns true or false. ",[12,22,23],{},"In the case of List\u003CT> it is possible to pass it a delegate that is a function that returns true or false.",[12,25,26],{},"In the examples below I have base object a generic collection of those objects and am using the FindAll method to return only a few of the objects based on matching criteria.  There are a number of samples, just un-comment the ones of interest.   ",[28,29,31,32,37,38,41,42,46,47,49,50,37,53,56,57,46,59,61,62,66,67,70,71,37,74,76,77,46,79,61,81,66,83,70,86,37,89,91,92,46,94,61,96,66,99,70,102,105,106,109,110,113,114,117,118,37,121,129,130,37,133,129,136,37,139,129,142,37,145,129,148,37,151,129,154,117,157,37,160,129,163,37,166,129,169,117,172,37,175,129,178,37,181,129,184,37,187,129,190,117,193,37,196,129,201,37,204,207,208,210,211,46,213,61,216,218,219,222,223,226,227,117,230,117,233,37,236,129,241,37,244,129,247,37,250,129,253,37,256,259,117,262,117,265,37,268,129,273,37,276,129,282,37,285,129,288,37,291,129,294,37,297,129,300,37,303,129,306,37,309,129,312,37,315,129,318,37,321,129,324,37,327,129,330,37,333,129,336,117,339,37,342,129,345,37,348,129,353,37,356,129,359,37,362,129,365,37,368,129,371,37,374,129,377,37,380,129,383,37,386,129,389,37,392,129,394,37,397,129,399,37,402,46],"div",{"style":30},"font-size: 8pt; background: white; color: black; font-family: consolas","   ",[33,34,36],"span",{"style":35},"color: #2b91af","   23","             ",[33,39,40],{"style":35},"Persons"," personList = ",[33,43,45],{"style":44},"color: blue","new"," ",[33,48,40],{"style":35},"();    ",[33,51,52],{"style":35},"   24",[33,54,55],{"style":35},"Person"," p1 = ",[33,58,45],{"style":44},[33,60,55],{"style":35},"(",[33,63,65],{"style":64},"color: #a31515","\"Rose\"",", ",[33,68,69],{"style":64},"\"Bob\"",");    ",[33,72,73],{"style":35},"   25",[33,75,55],{"style":35}," p2 = ",[33,78,45],{"style":44},[33,80,55],{"style":35},[33,82,65],{"style":64},[33,84,85],{"style":64},"\"Phil\"",[33,87,88],{"style":35},"   26",[33,90,55],{"style":35}," p3 = ",[33,93,45],{"style":44},[33,95,55],{"style":35},[33,97,98],{"style":64},"\"Smith\"",[33,100,101],{"style":64},"\"Jack\"",[33,103,104],{"style":35},"   27","             personList.Add(p1);    ",[33,107,108],{"style":35},"   28","             personList.Add(p2);    ",[33,111,112],{"style":35},"   29","             personList.Add(p3);    ",[33,115,116],{"style":35},"   30","     ",[33,119,120],{"style":35},"   31",[33,122,124,125],{"style":123},"color: green","\u002F\u002F",[126,127,128],"strong",{},"Sample 1 Using Predicate Technique (long form)","    ",[33,131,132],{"style":35},"   32",[33,134,135],{"style":123},"\u002F\u002FPredicate\u003CPerson> filterByLastName;",[33,137,138],{"style":35},"   33",[33,140,141],{"style":123},"\u002F\u002FPersonFilter filter = new PersonFilter(\"Rose\");",[33,143,144],{"style":35},"   34",[33,146,147],{"style":123},"\u002F\u002FfilterByLastName = new Predicate\u003CPerson>(filter.FilterByLastName);",[33,149,150],{"style":35},"   35",[33,152,153],{"style":123},"\u002F\u002FList\u003CPerson> list = personList.FindAll(filterByLastName);",[33,155,156],{"style":35},"   36",[33,158,159],{"style":35},"   37",[33,161,162],{"style":123},"\u002F\u002FResponse.Write(\"Original Collection Count \" + personList.Count.ToString() + \"\u003Cbr \u002F>\");",[33,164,165],{"style":35},"   38",[33,167,168],{"style":123},"\u002F\u002FResponse.Write(\"Filtered List Count \" + list.Count.ToString() + \"\u003Cbr \u002F>\");",[33,170,171],{"style":35},"   39",[33,173,174],{"style":35},"   40",[33,176,177],{"style":123},"\u002F\u002F\u002F\u002F this is a shorter version and uses the RemoveAll method to items",[33,179,180],{"style":35},"   41",[33,182,183],{"style":123},"\u002F\u002FpersonList.RemoveAll(filterByLastName);",[33,185,186],{"style":35},"   42",[33,188,189],{"style":123},"\u002F\u002FResponse.Write(\"After persons removed from the collection Count \" + personList.Count.ToString());",[33,191,192],{"style":35},"   43",[33,194,195],{"style":35},"   44",[33,197,124,198],{"style":123},[126,199,200],{},"Sample 2 shortform version",[33,202,203],{"style":35},"   45",[33,205,206],{"style":35},"List","\u003C",[33,209,55],{"style":35},"> list2 = personList.FindAll(",[33,212,45],{"style":44},[33,214,215],{"style":35},"PersonFilter",[33,217,65],{"style":64},").FilterByLastName);    ",[33,220,221],{"style":35},"   46","             Response.Write(",[33,224,225],{"style":64},"\"Count \""," + list2.Count.ToString());",[33,228,229],{"style":35},"   47",[33,231,232],{"style":35},"   48",[33,234,235],{"style":35},"   49",[33,237,124,238],{"style":123},[126,239,240],{},"Sample 3 using lambda expression",[33,242,243],{"style":35},"   50",[33,245,246],{"style":123},"\u002F\u002FList\u003CPerson> list3 = personList.FindAll(",[33,248,249],{"style":35},"   51",[33,251,252],{"style":123},"\u002F\u002F    r => r.LastName == \"Rose\");",[33,254,255],{"style":35},"   52",[33,257,258],{"style":123},"\u002F\u002FResponse.Write(\"Count \" + list3.Count.ToString());",[33,260,261],{"style":35},"   53",[33,263,264],{"style":35},"   54",[33,266,267],{"style":35},"   55",[33,269,124,270],{"style":123},[126,271,272],{},"Sample 4 with arrays",[33,274,275],{"style":35},"   56",[33,277,278,279,281],{"style":123},"\u002F\u002FPerson",[33,280],{}," personList2 = {",[33,283,284],{"style":35},"   57",[33,286,287],{"style":123},"\u002F\u002F   new Person(\"Rose\", \"Bob\"),",[33,289,290],{"style":35},"   58",[33,292,293],{"style":123},"\u002F\u002F   new Person(\"Rose\", \"Phil\"),",[33,295,296],{"style":35},"   59",[33,298,299],{"style":123},"\u002F\u002F   new Person(\"Smith\", \"Jack\"),",[33,301,302],{"style":35},"   60",[33,304,305],{"style":123},"\u002F\u002F};",[33,307,308],{"style":35},"   61",[33,310,311],{"style":123},"\u002F\u002Foutputs each person in array",[33,313,314],{"style":35},"   62",[33,316,317],{"style":123},"\u002F\u002FArray.ForEach(personList2, delegate(Person p)",[33,319,320],{"style":35},"   63",[33,322,323],{"style":123},"\u002F\u002F{",[33,325,326],{"style":35},"   64",[33,328,329],{"style":123},"\u002F\u002F    Response.Write(p.LastName + \"\u003Cbr \u002F>\");",[33,331,332],{"style":35},"   65",[33,334,335],{"style":123},"\u002F\u002F});",[33,337,338],{"style":35},"   66",[33,340,341],{"style":35},"   67",[33,343,344],{"style":123},"\u002F\u002Foutputs each person after findall",[33,346,347],{"style":35},"   68",[33,349,278,350,352],{"style":123},[33,351],{}," personList3 = Array.FindAll(personList2, ",[33,354,355],{"style":35},"   69",[33,357,358],{"style":123},"\u002F\u002F    delegate (Person p)",[33,360,361],{"style":35},"   70",[33,363,364],{"style":123},"\u002F\u002F    {",[33,366,367],{"style":35},"   71",[33,369,370],{"style":123},"\u002F\u002F        return p.LastName == \"Rose\";",[33,372,373],{"style":35},"   72",[33,375,376],{"style":123},"\u002F\u002F    }",[33,378,379],{"style":35},"   73",[33,381,382],{"style":123},"\u002F\u002F);",[33,384,385],{"style":35},"   74",[33,387,388],{"style":123},"\u002F\u002FArray.ForEach(personList3, delegate(Person p)",[33,390,391],{"style":35},"   75",[33,393,323],{"style":123},[33,395,396],{"style":35},"   76",[33,398,329],{"style":123},[33,400,401],{"style":35},"   77",[33,403,335],{"style":123},[28,405,31,406,409,410,46,413,46,416,418,419,207,421,423,424,117,427,409,430,432,433,436,437,440,441,117,444,117,447,117,450,453,454,46,456,46,458,460,461,117,464,409,467,46,470,473,474,409,477,46,479,481,482,409,485,46,487,489,490,493,494,460,497,37,500,473,503,506,507,493,510,460,513,516,517,520,521,506,524,527,528,409,531,46,533,535,536,493,539,460,541,37,544,481,546,506,549,493,552,460,554,557,558,520,560,506,563,436,566,117,569,409,572,574,575,577,578,580,581,584,585,588,589,527,592,117,595,440,598,117,601,117,604,453,607,46,609,46,611,129,613,460,616,117,619,409,622,46,624,626,627,117,630,409,633,635,636,638,639,642,643,646,647,436,650,117,653,409,656,46,658,661,662,664,665,642,668,493,671,674,675,678,679,37,682,46,684,520,687,506,690,493,693,46,695,520,698,436,701,117,704,117,707,409,710,46,712,714,715,664,717,642,720,493,723,725,726,678,729,37,732,46,734,520,736,506,739,493,742,46,744,520,746,436,749,752],{"style":30},[33,407,408],{"style":35},"   86","     ",[33,411,412],{"style":44},"public",[33,414,415],{"style":44},"class",[33,417,40],{"style":35}," : System.Collections.Generic.",[33,420,206],{"style":35},[33,422,55],{"style":35},"> {    ",[33,425,426],{"style":35},"   87",[33,428,429],{"style":35},"   88",[33,431,412],{"style":44}," Persons() {    ",[33,434,435],{"style":35},"   89","     }    ",[33,438,439],{"style":35},"   90"," }    ",[33,442,443],{"style":35},"   91",[33,445,446],{"style":35},"   92",[33,448,449],{"style":35},"   93",[33,451,452],{"style":35},"   94"," ",[33,455,412],{"style":44},[33,457,415],{"style":44},[33,459,55],{"style":35}," {    ",[33,462,463],{"style":35},"   95",[33,465,466],{"style":35},"   96",[33,468,469],{"style":44},"private",[33,471,472],{"style":44},"string"," _lastName;    ",[33,475,476],{"style":35},"   97",[33,478,469],{"style":44},[33,480,472],{"style":44}," _firstName;    ",[33,483,484],{"style":35},"   98",[33,486,412],{"style":44},[33,488,472],{"style":44}," LastName {    ",[33,491,492],{"style":35},"   99","         ",[33,495,496],{"style":44},"get",[33,498,499],{"style":35},"  100",[33,501,502],{"style":44},"return",[33,504,505],{"style":35},"  101","         }    ",[33,508,509],{"style":35},"  102",[33,511,512],{"style":44},"set",[33,514,515],{"style":35},"  103","             _lastName = ",[33,518,519],{"style":44},"value",";    ",[33,522,523],{"style":35},"  104",[33,525,526],{"style":35},"  105","     }        ",[33,529,530],{"style":35},"  106",[33,532,412],{"style":44},[33,534,472],{"style":44}," FirstName {    ",[33,537,538],{"style":35},"  107",[33,540,496],{"style":44},[33,542,543],{"style":35},"  108",[33,545,502],{"style":44},[33,547,548],{"style":35},"  109",[33,550,551],{"style":35},"  110",[33,553,512],{"style":44},[33,555,556],{"style":35},"  111","             _firstName = ",[33,559,519],{"style":44},[33,561,562],{"style":35},"  112",[33,564,565],{"style":35},"  113",[33,567,568],{"style":35},"  114",[33,570,571],{"style":35},"  115",[33,573,412],{"style":44}," Person(",[33,576,472],{"style":44}," lastName, ",[33,579,472],{"style":44}," firstName) {    ",[33,582,583],{"style":35},"  116","         _lastName = lastName;    ",[33,586,587],{"style":35},"  117","         _firstName = firstName;    ",[33,590,591],{"style":35},"  118",[33,593,594],{"style":35},"  119",[33,596,597],{"style":35},"  120",[33,599,600],{"style":35},"  121",[33,602,603],{"style":35},"  122",[33,605,606],{"style":35},"  123",[33,608,412],{"style":44},[33,610,415],{"style":44},[33,612,215],{"style":35},[33,614,615],{"style":35},"  124",[33,617,618],{"style":35},"  125",[33,620,621],{"style":35},"  126",[33,623,469],{"style":44},[33,625,472],{"style":44}," _match;    ",[33,628,629],{"style":35},"  127",[33,631,632],{"style":35},"  128",[33,634,412],{"style":44}," PersonFilter(",[33,637,472],{"style":44}," match)    ",[33,640,641],{"style":35},"  129","     {    ",[33,644,645],{"style":35},"  130","         _match = match;    ",[33,648,649],{"style":35},"  131",[33,651,652],{"style":35},"  132",[33,654,655],{"style":35},"  133",[33,657,412],{"style":44},[33,659,660],{"style":44},"bool"," FilterByLastName(",[33,663,55],{"style":35}," per)    ",[33,666,667],{"style":35},"  134",[33,669,670],{"style":35},"  135",[33,672,673],{"style":44},"if"," (per.LastName == _match)    ",[33,676,677],{"style":35},"  136","         {    ",[33,680,681],{"style":35},"  137",[33,683,502],{"style":44},[33,685,686],{"style":44},"true",[33,688,689],{"style":35},"  138",[33,691,692],{"style":35},"  139",[33,694,502],{"style":44},[33,696,697],{"style":44},"false",[33,699,700],{"style":35},"  140",[33,702,703],{"style":35},"  141",[33,705,706],{"style":35},"  142",[33,708,709],{"style":35},"  143",[33,711,412],{"style":44},[33,713,660],{"style":44}," FilterByFirstName(",[33,716,55],{"style":35},[33,718,719],{"style":35},"  144",[33,721,722],{"style":35},"  145",[33,724,673],{"style":44}," (per.FirstName == _match)    ",[33,727,728],{"style":35},"  146",[33,730,731],{"style":35},"  147",[33,733,502],{"style":44},[33,735,686],{"style":44},[33,737,738],{"style":35},"  148",[33,740,741],{"style":35},"  149",[33,743,502],{"style":44},[33,745,697],{"style":44},[33,747,748],{"style":35},"  150",[33,750,751],{"style":35},"  151"," } ",[754,755],"br",{},[757,758],"img",{"src":759,"alt":760,"style":761},"\u002Farticles\u002Fimages\u002Ffilter.jpg","","display:none;",{"title":760,"searchDepth":763,"depth":763,"links":764},2,[],"2017-05-29T20:59:15.8338506Z","md",{},true,"\u002Farticles\u002Fgeneric-collections-and-filtering",{"title":6,"description":14},"articles\u002Fgeneric-collections-and-filtering",[773],"csharp","fUAFW_aqKskOuF4PIpWXrn1qMk6NyjR1YFeTVoFP0Go",[776],{"id":777,"title":778,"body":779,"description":783,"extension":766,"img":784,"meta":785,"name":773,"navigation":768,"path":786,"seo":787,"stem":788,"__hash__":789},"tags\u002Ftags\u002Fcsharp.md","Csharp",{"type":9,"value":780,"toc":781},[],{"title":760,"searchDepth":763,"depth":763,"links":782},[],null,"https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"\u002Ftags\u002Fcsharp",{"description":783},"tags\u002Fcsharp","q__D01bgRc46igktetL1XSIb0CS3jpaQOtnTfdNZJyQ",{"id":791,"title":792,"author":7,"body":793,"createdAt":821,"description":822,"extension":766,"img":823,"meta":824,"navigation":768,"path":825,"seo":826,"stem":827,"tags":828,"updatedAt":821,"__hash__":831},"articles\u002Farticles\u002Fsql-server-2008-installation-ndash-not-so-quick.md","SQL Server 2008 Installation, not so quick",{"type":9,"value":794,"toc":819},[795,805,808,816],[12,796,797,798,804],{},"Before you rush to download SQL 2008 you may want to read the following KB article which warns that Visual Studio 2008 SP1 ‘may be required’ for SQL Server 2008 installations KB956139 (found ",[799,800,803],"a",{"href":801,"target":802},"http:\u002F\u002Fsupport.microsoft.com\u002Fkb\u002F956139","_blank","here",")",[12,806,807],{},"”Because certain SQL Server 2008 features install components that are also part of the release version of Visual Studio 2008 SP1, SQL Server 2008 requires Visual Studio 2008 with SP1. If Visual Studio 2008 without a service pack is installed instead, it may not work correctly after you install SQL Server 2008.“",[12,809,810,811,815],{},"Currently, ",[799,812,814],{"href":813,"target":802},"http:\u002F\u002Fmsdn.microsoft.com\u002Fen-us\u002Fvstudio\u002Fcc533448.aspx","Visual Studio 2008 Service Pack 1"," (SP1) is in beta at the current time.",[12,817,818],{},"I do not know the expected delivery of SP1 but should be soon (hang tight).",{"title":760,"searchDepth":763,"depth":763,"links":820},[],"2017-05-29T20:59:15.8643544Z","Before you rush to download SQL 2008 you may want to read the following KB article contained within this blog.","\u002Farticles\u002Fimages\u002Fl2oWZnThPG.png",{},"\u002Farticles\u002Fsql-server-2008-installation-ndash-not-so-quick",{"title":792,"description":822},"articles\u002Fsql-server-2008-installation-ndash-not-so-quick",[829,830],"sqlserver","sql","uUgrYz6hVSOWfcqo-ApYDrtjGpXT3uL0jd9PBGOi3E8",{"id":833,"title":834,"author":7,"body":835,"createdAt":871,"description":872,"extension":766,"img":866,"meta":873,"navigation":768,"path":874,"seo":875,"stem":876,"tags":877,"updatedAt":871,"__hash__":879},"articles\u002Farticles\u002Ftelerik-reporting-and-really-impressive.md","Telerik Reporting and Really Impressive",{"type":9,"value":836,"toc":869},[837,840,843,846,849,856],[12,838,839],{},"My experience with the relatively new Telerik reporting solution has been very positive.  In order to create a report you simply need a 3 dll’s within your solution and a data source.    The data source can be ANY ADO.NET data source as well as business objects, XML, Web Services etc. ",[12,841,842],{},"As the data source can be any ADO.NET source the reporting solution works against SQL Server, MySQL, Oracle, Access, OLE DB etc.  I have been a big fan of SQL Reporting Services for quite a while (moving to SQL RS many years ago as I ran from Crystal Reports). ",[12,844,845],{},"Unlike SQL RS it is a very fast install on local development workstation and nothing on the server is required.  The product is licensed by developer making utilization by the enterprise not dependent on the number of users.  This really works out well in the Internet type environment.    I found the the designer (within Visual Studio) to be very fast and easier to use that SQL RS.  The drag and drop features and the visual clues are clearly superior than other reporting solutions I have used.",[12,847,848],{},"Telerik Reporting supports the most commonly used output formats out-of-the-box: PDF, Excel, RTF, CSV, MHTML, BMP, GIF, JPEG, PNG, TIFF and metafile (EMF).  The Telerik product certainly makes it easy to find the data source, connect within Visual Studio and drag and drop the fields onto the design surface.",[12,850,851,852],{},"More information can be found online at ",[799,853,855],{"href":854,"target":802},"http:\u002F\u002Fwww.telerik.com\u002Fproducts\u002Freporting\u002Foverview.aspx","Telerik Reporting",[12,857,858],{},[799,859,861],{"href":860},"\u002Farticles\u002Fimages\u002Fimage_4.png",[757,862],{"title":863,"style":864,"height":865,"alt":863,"src":866,"width":867,"border":868},"image","border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px",110,"\u002Farticles\u002Fimages\u002Fimage_thumb_1.png",244,0,{"title":760,"searchDepth":763,"depth":763,"links":870},[],"2017-05-29T20:59:15.8038514Z","Experience with Telerik Reporting",{},"\u002Farticles\u002Ftelerik-reporting-and-really-impressive",{"title":834,"description":872},"articles\u002Ftelerik-reporting-and-really-impressive",[878],"visualstudio","VnOxxF6UPPJZuAeC8AeVTJrgkQ8VbTy23tLzCccb3Vs",1781574763319]