[{"data":1,"prerenderedAt":1362},["ShallowReactive",2],{"tag-csharp":3},{"tag":4,"articles":24},{"id":5,"title":6,"body":7,"description":14,"extension":15,"img":16,"meta":17,"name":18,"navigation":19,"path":20,"seo":21,"stem":22,"__hash__":23},"tags\u002Ftags\u002Fcsharp.md","Csharp",{"type":8,"value":9,"toc":10},"minimark",[],{"title":11,"searchDepth":12,"depth":12,"links":13},"",2,[],null,"md","https:\u002F\u002Fimages.unsplash.com\u002Fphoto-1598313183973-4effcded8d5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=675&q=80",{},"csharp",true,"\u002Ftags\u002Fcsharp",{"description":14},"tags\u002Fcsharp","q__D01bgRc46igktetL1XSIb0CS3jpaQOtnTfdNZJyQ",[25,790,1092,1141,1222],{"id":26,"title":27,"author":28,"body":29,"createdAt":783,"description":34,"extension":15,"img":779,"meta":784,"navigation":19,"path":785,"seo":786,"stem":787,"tags":788,"updatedAt":783,"__hash__":789},"articles\u002Farticles\u002Fgeneric-collections-and-filtering.md","Generic Collections and Filtering","[object Object]",{"type":8,"value":30,"toc":781},[31,35,38,41,44,47,424,773,776],[32,33,34],"p",{},"When dealing with collections the common question is how to filter them based on criteria. ",[32,36,37],{},"The following are a few techniques used to accomplish this.  A delegate is like a function pointer. ",[32,39,40],{},"A predicate is a method that returns true or false. ",[32,42,43],{},"In the case of List\u003CT> it is possible to pass it a delegate that is a function that returns true or false.",[32,45,46],{},"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.   ",[48,49,51,52,57,58,61,62,66,67,69,70,57,73,76,77,66,79,81,82,86,87,90,91,57,94,96,97,66,99,81,101,86,103,90,106,57,109,111,112,66,114,81,116,86,119,90,122,125,126,129,130,133,134,137,138,57,141,149,150,57,153,149,156,57,159,149,162,57,165,149,168,57,171,149,174,137,177,57,180,149,183,57,186,149,189,137,192,57,195,149,198,57,201,149,204,57,207,149,210,137,213,57,216,149,221,57,224,227,228,230,231,66,233,81,236,238,239,242,243,246,247,137,250,137,253,57,256,149,261,57,264,149,267,57,270,149,273,57,276,279,137,282,137,285,57,288,149,293,57,296,149,302,57,305,149,308,57,311,149,314,57,317,149,320,57,323,149,326,57,329,149,332,57,335,149,338,57,341,149,344,57,347,149,350,57,353,149,356,137,359,57,362,149,365,57,368,149,373,57,376,149,379,57,382,149,385,57,388,149,391,57,394,149,397,57,400,149,403,57,406,149,409,57,412,149,414,57,417,149,419,57,422,66],"div",{"style":50},"font-size: 8pt; background: white; color: black; font-family: consolas","   ",[53,54,56],"span",{"style":55},"color: #2b91af","   23","             ",[53,59,60],{"style":55},"Persons"," personList = ",[53,63,65],{"style":64},"color: blue","new"," ",[53,68,60],{"style":55},"();    ",[53,71,72],{"style":55},"   24",[53,74,75],{"style":55},"Person"," p1 = ",[53,78,65],{"style":64},[53,80,75],{"style":55},"(",[53,83,85],{"style":84},"color: #a31515","\"Rose\"",", ",[53,88,89],{"style":84},"\"Bob\"",");    ",[53,92,93],{"style":55},"   25",[53,95,75],{"style":55}," p2 = ",[53,98,65],{"style":64},[53,100,75],{"style":55},[53,102,85],{"style":84},[53,104,105],{"style":84},"\"Phil\"",[53,107,108],{"style":55},"   26",[53,110,75],{"style":55}," p3 = ",[53,113,65],{"style":64},[53,115,75],{"style":55},[53,117,118],{"style":84},"\"Smith\"",[53,120,121],{"style":84},"\"Jack\"",[53,123,124],{"style":55},"   27","             personList.Add(p1);    ",[53,127,128],{"style":55},"   28","             personList.Add(p2);    ",[53,131,132],{"style":55},"   29","             personList.Add(p3);    ",[53,135,136],{"style":55},"   30","     ",[53,139,140],{"style":55},"   31",[53,142,144,145],{"style":143},"color: green","\u002F\u002F",[146,147,148],"strong",{},"Sample 1 Using Predicate Technique (long form)","    ",[53,151,152],{"style":55},"   32",[53,154,155],{"style":143},"\u002F\u002FPredicate\u003CPerson> filterByLastName;",[53,157,158],{"style":55},"   33",[53,160,161],{"style":143},"\u002F\u002FPersonFilter filter = new PersonFilter(\"Rose\");",[53,163,164],{"style":55},"   34",[53,166,167],{"style":143},"\u002F\u002FfilterByLastName = new Predicate\u003CPerson>(filter.FilterByLastName);",[53,169,170],{"style":55},"   35",[53,172,173],{"style":143},"\u002F\u002FList\u003CPerson> list = personList.FindAll(filterByLastName);",[53,175,176],{"style":55},"   36",[53,178,179],{"style":55},"   37",[53,181,182],{"style":143},"\u002F\u002FResponse.Write(\"Original Collection Count \" + personList.Count.ToString() + \"\u003Cbr \u002F>\");",[53,184,185],{"style":55},"   38",[53,187,188],{"style":143},"\u002F\u002FResponse.Write(\"Filtered List Count \" + list.Count.ToString() + \"\u003Cbr \u002F>\");",[53,190,191],{"style":55},"   39",[53,193,194],{"style":55},"   40",[53,196,197],{"style":143},"\u002F\u002F\u002F\u002F this is a shorter version and uses the RemoveAll method to items",[53,199,200],{"style":55},"   41",[53,202,203],{"style":143},"\u002F\u002FpersonList.RemoveAll(filterByLastName);",[53,205,206],{"style":55},"   42",[53,208,209],{"style":143},"\u002F\u002FResponse.Write(\"After persons removed from the collection Count \" + personList.Count.ToString());",[53,211,212],{"style":55},"   43",[53,214,215],{"style":55},"   44",[53,217,144,218],{"style":143},[146,219,220],{},"Sample 2 shortform version",[53,222,223],{"style":55},"   45",[53,225,226],{"style":55},"List","\u003C",[53,229,75],{"style":55},"> list2 = personList.FindAll(",[53,232,65],{"style":64},[53,234,235],{"style":55},"PersonFilter",[53,237,85],{"style":84},").FilterByLastName);    ",[53,240,241],{"style":55},"   46","             Response.Write(",[53,244,245],{"style":84},"\"Count \""," + list2.Count.ToString());",[53,248,249],{"style":55},"   47",[53,251,252],{"style":55},"   48",[53,254,255],{"style":55},"   49",[53,257,144,258],{"style":143},[146,259,260],{},"Sample 3 using lambda expression",[53,262,263],{"style":55},"   50",[53,265,266],{"style":143},"\u002F\u002FList\u003CPerson> list3 = personList.FindAll(",[53,268,269],{"style":55},"   51",[53,271,272],{"style":143},"\u002F\u002F    r => r.LastName == \"Rose\");",[53,274,275],{"style":55},"   52",[53,277,278],{"style":143},"\u002F\u002FResponse.Write(\"Count \" + list3.Count.ToString());",[53,280,281],{"style":55},"   53",[53,283,284],{"style":55},"   54",[53,286,287],{"style":55},"   55",[53,289,144,290],{"style":143},[146,291,292],{},"Sample 4 with arrays",[53,294,295],{"style":55},"   56",[53,297,298,299,301],{"style":143},"\u002F\u002FPerson",[53,300],{}," personList2 = {",[53,303,304],{"style":55},"   57",[53,306,307],{"style":143},"\u002F\u002F   new Person(\"Rose\", \"Bob\"),",[53,309,310],{"style":55},"   58",[53,312,313],{"style":143},"\u002F\u002F   new Person(\"Rose\", \"Phil\"),",[53,315,316],{"style":55},"   59",[53,318,319],{"style":143},"\u002F\u002F   new Person(\"Smith\", \"Jack\"),",[53,321,322],{"style":55},"   60",[53,324,325],{"style":143},"\u002F\u002F};",[53,327,328],{"style":55},"   61",[53,330,331],{"style":143},"\u002F\u002Foutputs each person in array",[53,333,334],{"style":55},"   62",[53,336,337],{"style":143},"\u002F\u002FArray.ForEach(personList2, delegate(Person p)",[53,339,340],{"style":55},"   63",[53,342,343],{"style":143},"\u002F\u002F{",[53,345,346],{"style":55},"   64",[53,348,349],{"style":143},"\u002F\u002F    Response.Write(p.LastName + \"\u003Cbr \u002F>\");",[53,351,352],{"style":55},"   65",[53,354,355],{"style":143},"\u002F\u002F});",[53,357,358],{"style":55},"   66",[53,360,361],{"style":55},"   67",[53,363,364],{"style":143},"\u002F\u002Foutputs each person after findall",[53,366,367],{"style":55},"   68",[53,369,298,370,372],{"style":143},[53,371],{}," personList3 = Array.FindAll(personList2, ",[53,374,375],{"style":55},"   69",[53,377,378],{"style":143},"\u002F\u002F    delegate (Person p)",[53,380,381],{"style":55},"   70",[53,383,384],{"style":143},"\u002F\u002F    {",[53,386,387],{"style":55},"   71",[53,389,390],{"style":143},"\u002F\u002F        return p.LastName == \"Rose\";",[53,392,393],{"style":55},"   72",[53,395,396],{"style":143},"\u002F\u002F    }",[53,398,399],{"style":55},"   73",[53,401,402],{"style":143},"\u002F\u002F);",[53,404,405],{"style":55},"   74",[53,407,408],{"style":143},"\u002F\u002FArray.ForEach(personList3, delegate(Person p)",[53,410,411],{"style":55},"   75",[53,413,343],{"style":143},[53,415,416],{"style":55},"   76",[53,418,349],{"style":143},[53,420,421],{"style":55},"   77",[53,423,355],{"style":143},[48,425,51,426,429,430,66,433,66,436,438,439,227,441,443,444,137,447,429,450,452,453,456,457,460,461,137,464,137,467,137,470,473,474,66,476,66,478,480,481,137,484,429,487,66,490,493,494,429,497,66,499,501,502,429,505,66,507,509,510,513,514,480,517,57,520,493,523,526,527,513,530,480,533,536,537,540,541,526,544,547,548,429,551,66,553,555,556,513,559,480,561,57,564,501,566,526,569,513,572,480,574,577,578,540,580,526,583,456,586,137,589,429,592,594,595,597,598,600,601,604,605,608,609,547,612,137,615,460,618,137,621,137,624,473,627,66,629,66,631,149,633,480,636,137,639,429,642,66,644,646,647,137,650,429,653,655,656,658,659,662,663,666,667,456,670,137,673,429,676,66,678,681,682,684,685,662,688,513,691,694,695,698,699,57,702,66,704,540,707,526,710,513,713,66,715,540,718,456,721,137,724,137,727,429,730,66,732,734,735,684,737,662,740,513,743,745,746,698,749,57,752,66,754,540,756,526,759,513,762,66,764,540,766,456,769,772],{"style":50},[53,427,428],{"style":55},"   86","     ",[53,431,432],{"style":64},"public",[53,434,435],{"style":64},"class",[53,437,60],{"style":55}," : System.Collections.Generic.",[53,440,226],{"style":55},[53,442,75],{"style":55},"> {    ",[53,445,446],{"style":55},"   87",[53,448,449],{"style":55},"   88",[53,451,432],{"style":64}," Persons() {    ",[53,454,455],{"style":55},"   89","     }    ",[53,458,459],{"style":55},"   90"," }    ",[53,462,463],{"style":55},"   91",[53,465,466],{"style":55},"   92",[53,468,469],{"style":55},"   93",[53,471,472],{"style":55},"   94"," ",[53,475,432],{"style":64},[53,477,435],{"style":64},[53,479,75],{"style":55}," {    ",[53,482,483],{"style":55},"   95",[53,485,486],{"style":55},"   96",[53,488,489],{"style":64},"private",[53,491,492],{"style":64},"string"," _lastName;    ",[53,495,496],{"style":55},"   97",[53,498,489],{"style":64},[53,500,492],{"style":64}," _firstName;    ",[53,503,504],{"style":55},"   98",[53,506,432],{"style":64},[53,508,492],{"style":64}," LastName {    ",[53,511,512],{"style":55},"   99","         ",[53,515,516],{"style":64},"get",[53,518,519],{"style":55},"  100",[53,521,522],{"style":64},"return",[53,524,525],{"style":55},"  101","         }    ",[53,528,529],{"style":55},"  102",[53,531,532],{"style":64},"set",[53,534,535],{"style":55},"  103","             _lastName = ",[53,538,539],{"style":64},"value",";    ",[53,542,543],{"style":55},"  104",[53,545,546],{"style":55},"  105","     }        ",[53,549,550],{"style":55},"  106",[53,552,432],{"style":64},[53,554,492],{"style":64}," FirstName {    ",[53,557,558],{"style":55},"  107",[53,560,516],{"style":64},[53,562,563],{"style":55},"  108",[53,565,522],{"style":64},[53,567,568],{"style":55},"  109",[53,570,571],{"style":55},"  110",[53,573,532],{"style":64},[53,575,576],{"style":55},"  111","             _firstName = ",[53,579,539],{"style":64},[53,581,582],{"style":55},"  112",[53,584,585],{"style":55},"  113",[53,587,588],{"style":55},"  114",[53,590,591],{"style":55},"  115",[53,593,432],{"style":64}," Person(",[53,596,492],{"style":64}," lastName, ",[53,599,492],{"style":64}," firstName) {    ",[53,602,603],{"style":55},"  116","         _lastName = lastName;    ",[53,606,607],{"style":55},"  117","         _firstName = firstName;    ",[53,610,611],{"style":55},"  118",[53,613,614],{"style":55},"  119",[53,616,617],{"style":55},"  120",[53,619,620],{"style":55},"  121",[53,622,623],{"style":55},"  122",[53,625,626],{"style":55},"  123",[53,628,432],{"style":64},[53,630,435],{"style":64},[53,632,235],{"style":55},[53,634,635],{"style":55},"  124",[53,637,638],{"style":55},"  125",[53,640,641],{"style":55},"  126",[53,643,489],{"style":64},[53,645,492],{"style":64}," _match;    ",[53,648,649],{"style":55},"  127",[53,651,652],{"style":55},"  128",[53,654,432],{"style":64}," PersonFilter(",[53,657,492],{"style":64}," match)    ",[53,660,661],{"style":55},"  129","     {    ",[53,664,665],{"style":55},"  130","         _match = match;    ",[53,668,669],{"style":55},"  131",[53,671,672],{"style":55},"  132",[53,674,675],{"style":55},"  133",[53,677,432],{"style":64},[53,679,680],{"style":64},"bool"," FilterByLastName(",[53,683,75],{"style":55}," per)    ",[53,686,687],{"style":55},"  134",[53,689,690],{"style":55},"  135",[53,692,693],{"style":64},"if"," (per.LastName == _match)    ",[53,696,697],{"style":55},"  136","         {    ",[53,700,701],{"style":55},"  137",[53,703,522],{"style":64},[53,705,706],{"style":64},"true",[53,708,709],{"style":55},"  138",[53,711,712],{"style":55},"  139",[53,714,522],{"style":64},[53,716,717],{"style":64},"false",[53,719,720],{"style":55},"  140",[53,722,723],{"style":55},"  141",[53,725,726],{"style":55},"  142",[53,728,729],{"style":55},"  143",[53,731,432],{"style":64},[53,733,680],{"style":64}," FilterByFirstName(",[53,736,75],{"style":55},[53,738,739],{"style":55},"  144",[53,741,742],{"style":55},"  145",[53,744,693],{"style":64}," (per.FirstName == _match)    ",[53,747,748],{"style":55},"  146",[53,750,751],{"style":55},"  147",[53,753,522],{"style":64},[53,755,706],{"style":64},[53,757,758],{"style":55},"  148",[53,760,761],{"style":55},"  149",[53,763,522],{"style":64},[53,765,717],{"style":64},[53,767,768],{"style":55},"  150",[53,770,771],{"style":55},"  151"," } ",[774,775],"br",{},[777,778],"img",{"src":779,"alt":11,"style":780},"\u002Farticles\u002Fimages\u002Ffilter.jpg","display:none;",{"title":11,"searchDepth":12,"depth":12,"links":782},[],"2017-05-29T20:59:15.8338506Z",{},"\u002Farticles\u002Fgeneric-collections-and-filtering",{"title":27,"description":34},"articles\u002Fgeneric-collections-and-filtering",[18],"fUAFW_aqKskOuF4PIpWXrn1qMk6NyjR1YFeTVoFP0Go",{"id":791,"title":792,"author":28,"body":793,"createdAt":1085,"description":14,"extension":15,"img":1074,"meta":1086,"navigation":19,"path":1087,"seo":1088,"stem":1089,"tags":1090,"updatedAt":1085,"__hash__":1091},"articles\u002Farticles\u002Fc-6-0-new-features.md","C# 6.0 New Features",{"type":8,"value":794,"toc":1083},[795,798,804,824,839,851,908,913,922,925,940,954,979,985,994,997,1012,1018,1028,1033,1063,1079],[32,796,797],{},"The following features require the C# 6.0 compiler which is included in Visual Studio 2015.  Remarkably however C# 6 new features does not require and updated version of Microsoft .NET Framework (i.e. as long as you compile with VS.NET 2015 the features still work against .NET Framework 4).  This is possible as the features are implemented in the compiler itself and do not have dependencies on the .NET Framework.",[32,799,800,801,803],{},"1.) Using Static",[774,802],{},"\nUsing static directives for System.ConsoleColor looks like (as well as System.IO.Directory)",[805,806,809],"pre",{"className":807,"code":808,"language":18,"meta":11,"style":11},"language-csharp shiki shiki-themes github-light github-dark","using static System.ConsoleColor;  \nusing static System.IO.Directory;  \n",[810,811,812,819],"code",{"__ignoreMap":11},[53,813,816],{"class":814,"line":815},"line",1,[53,817,818],{},"using static System.ConsoleColor;  \n",[53,820,821],{"class":814,"line":12},[53,822,823],{},"using static System.IO.Directory;\n",[805,825,827],{"className":807,"code":826,"language":18,"meta":11,"style":11},"ForegroundColor = Yellow;  \nstring[] files = GetFiles(directoryPath, searchPattern, System.IO.SearchOption.AllDirectories);  \n",[810,828,829,834],{"__ignoreMap":11},[53,830,831],{"class":814,"line":815},[53,832,833],{},"ForegroundColor = Yellow;  \n",[53,835,836],{"class":814,"line":12},[53,837,838],{},"string[] files = GetFiles(directoryPath, searchPattern, System.IO.SearchOption.AllDirectories);\n",[32,840,841,842,844,845,847,848,850],{},"These enable the invocation of numerous methods, properties and enums directly.  In each case, this eliminates the need to qualify the static member with its type.",[774,843],{},"\n ",[774,846],{},"\n2.) The nameof operator",[774,849],{},"\nThis is a new contextual keyword to identify a string literal that extracts a constant for (at compile time) the unqualified name of whatever identifier is specified as an argument.  The nameof(filename) returns “filename,” the name of the Encrypt method’s parameter.  However, nameof works with any programmatic identifier.  By leveraging the nameof operator, it’s possible to eliminate the vast majority of “magic” strings that refer to code identifiers as long as they’re in scope. This not only eliminates runtime errors due to misspellings within the magic strings, which are never verified by the complier, but also enables refactoring tools like Rename to update all references to the name change identifier.",[805,852,854],{"className":807,"code":853,"language":18,"meta":11,"style":11},"private static void Encrypt(string filename)  \n  {  \n    if (!Exists(filename)) \u002F\u002F LOGIC ERROR: Using Directory rather than File  \n    {  \n      throw new ArgumentException(\"The file does not exist.\",   \n        nameof(filename));  \n    }  \n    \u002F\u002F ...  \n  }\n",[810,855,856,861,866,872,878,884,890,896,902],{"__ignoreMap":11},[53,857,858],{"class":814,"line":815},[53,859,860],{},"private static void Encrypt(string filename)  \n",[53,862,863],{"class":814,"line":12},[53,864,865],{},"  {  \n",[53,867,869],{"class":814,"line":868},3,[53,870,871],{},"    if (!Exists(filename)) \u002F\u002F LOGIC ERROR: Using Directory rather than File  \n",[53,873,875],{"class":814,"line":874},4,[53,876,877],{},"    {  \n",[53,879,881],{"class":814,"line":880},5,[53,882,883],{},"      throw new ArgumentException(\"The file does not exist.\",   \n",[53,885,887],{"class":814,"line":886},6,[53,888,889],{},"        nameof(filename));  \n",[53,891,893],{"class":814,"line":892},7,[53,894,895],{},"    }  \n",[53,897,899],{"class":814,"line":898},8,[53,900,901],{},"    \u002F\u002F ...  \n",[53,903,905],{"class":814,"line":904},9,[53,906,907],{},"  }\n",[32,909,473,910,912],{},[774,911],{},"\n3.) String Interpolation – this is an easier one to grasp.  This is the before syntax…",[805,914,916],{"className":807,"code":915,"language":18,"meta":11,"style":11},"string.Format(\"Hello!  My name is {0} {1} and I am {2} years old.\", person.FirstName, person.LastName, person.Age);\n",[810,917,918],{"__ignoreMap":11},[53,919,920],{"class":814,"line":815},[53,921,915],{},[32,923,924],{},"after…",[805,926,928],{"className":807,"code":927,"language":18,"meta":11,"style":11},"$\"Hello!  My name is {person.FirstName} {person.LastName} \n            and I am {person.Age} years old.\";\n",[810,929,930,935],{"__ignoreMap":11},[53,931,932],{"class":814,"line":815},[53,933,934],{},"$\"Hello!  My name is {person.FirstName} {person.LastName} \n",[53,936,937],{"class":814,"line":12},[53,938,939],{},"            and I am {person.Age} years old.\";\n",[32,941,942,943,844,945,947,948,950,951,953],{},"The string interpolation syntax reduces errors caused by arguments following the format string that are in improper order, or missing altogether and causing an exception.",[774,944],{},[774,946],{},"\n4.) Null-Conditional Operator",[774,949],{},"\nC# 6.0 introduces the “?.” operator known as the null-conditional operator.  The null-conditional operator translates to checking whether the operand is null prior to invoking the method or property.  What makes the null-conditional operator especially convenient is that it can be chained. If, for example, you invoke string",[53,952],{}," names = person?.Name?.Split(' '), Split will only be invoked if both person and person.Name are not null. When chained, if the first operand is null, the expression evaluation is short-circuited, and no further invocation within the expression call chain will occur.",[805,955,957],{"className":807,"code":956,"language":18,"meta":11,"style":11},"\u002F\u002Fafter  \nswitch (args?.Length) {}  \n\u002F\u002Fbefore  \n(args != null) ? (int?)args.Length : null  \n",[810,958,959,964,969,974],{"__ignoreMap":11},[53,960,961],{"class":814,"line":815},[53,962,963],{},"\u002F\u002Fafter  \n",[53,965,966],{"class":814,"line":12},[53,967,968],{},"switch (args?.Length) {}  \n",[53,970,971],{"class":814,"line":868},[53,972,973],{},"\u002F\u002Fbefore  \n",[53,975,976],{"class":814,"line":874},[53,977,978],{},"(args != null) ? (int?)args.Length : null\n",[32,980,981,982,984],{},"5.) Auto-Property Improvements",[774,983],{},"\nGetter-only auto-properties are a C# 6.0 feature for declaring read-only properties that are backed (internally) by a read-only field. As such, these properties can only be modified from within the constructor.  Rather than the six or so lines needed to declare a read-only property and initialize it prior to C# 6.0, now a single-line declaration and the assignment from within the constructor are all that’s needed.",[805,986,988],{"className":807,"code":987,"language":18,"meta":11,"style":11},"public ConsoleColor ForegroundColorVerbose { get; }\n",[810,989,990],{"__ignoreMap":11},[53,991,992],{"class":814,"line":815},[53,993,987],{},[32,995,996],{},"A second auto-property feature introduced in C# 6.0 is support for initializers.",[805,998,1000],{"className":807,"code":999,"language":18,"meta":11,"style":11},"static private Lazy\u003CConsoleConfiguration>\nDefaultConfig{ get; } = new Lazy\u003CConsoleConfiguration>(() => new ConsoleConfiguration());\n",[810,1001,1002,1007],{"__ignoreMap":11},[53,1003,1004],{"class":814,"line":815},[53,1005,1006],{},"static private Lazy\u003CConsoleConfiguration>\n",[53,1008,1009],{"class":814,"line":12},[53,1010,1011],{},"DefaultConfig{ get; } = new Lazy\u003CConsoleConfiguration>(() => new ConsoleConfiguration());\n",[32,1013,1014,1015,1017],{},"6.) Expression Bodied Methods and Auto-Properties",[774,1016],{},"\nThis feature exists for both properties and methods and allows the use of the arrow operator (=>) to assign an expression to either a property or method in place of a statement body.",[805,1019,1021],{"className":807,"code":1020,"language":18,"meta":11,"style":11},"static public ConsoleConfiguration GetDefault() => DefaultConfig.Value;  \n",[810,1022,1023],{"__ignoreMap":11},[53,1024,1025],{"class":814,"line":815},[53,1026,1027],{},"static public ConsoleConfiguration GetDefault() => DefaultConfig.Value;\n",[32,1029,473,1030,1032],{},[774,1031],{},"\n6.) Exception Improvements – ability to use a when clause to do additional filtering when an exception is thrown",[805,1034,1036],{"className":807,"code":1035,"language":18,"meta":11,"style":11},"try { \n        \u002F\u002F Do stuff\n    } catch (Exception e) when ((DateTime.Now.DayOfWeek == DayOfWeek.Saturday) {\n        \u002F\u002F Swallow \n    }\n",[810,1037,1038,1043,1048,1053,1058],{"__ignoreMap":11},[53,1039,1040],{"class":814,"line":815},[53,1041,1042],{},"try { \n",[53,1044,1045],{"class":814,"line":12},[53,1046,1047],{},"        \u002F\u002F Do stuff\n",[53,1049,1050],{"class":814,"line":868},[53,1051,1052],{},"    } catch (Exception e) when ((DateTime.Now.DayOfWeek == DayOfWeek.Saturday) {\n",[53,1054,1055],{"class":814,"line":874},[53,1056,1057],{},"        \u002F\u002F Swallow \n",[53,1059,1060],{"class":814,"line":880},[53,1061,1062],{},"    }\n",[32,1064,473,1065,1067],{},[774,1066],{},[1068,1069,1071],"a",{"href":1070},"\u002Farticles\u002Fimages\u002Fopen-live-writer-c-60-new-features_12307-c6_2.jpg",[777,1072],{"style":1073,"src":1074,"border":1075,"alt":1076,"title":1076,"width":1077,"height":1078},"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;","\u002Farticles\u002Fimages\u002Fopen-live-writer-c-60-new-features_12307-c6_thumb.jpg",0,"c6",240,135,[1080,1081,1082],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":11,"searchDepth":12,"depth":12,"links":1084},[],"2016-11-09T14:21:45.8700000-05:00",{},"\u002Farticles\u002Fc-6-0-new-features",{"title":792,"description":14},"articles\u002Fc-6-0-new-features",[18],"uMgZQ3TZwQfUVBOXbej-F7xUUHGEeZcIbN5MlW-pDw4",{"id":1093,"title":1094,"author":28,"body":1095,"createdAt":1132,"description":1133,"extension":15,"img":1134,"meta":1135,"navigation":19,"path":1136,"seo":1137,"stem":1138,"tags":1139,"updatedAt":1132,"__hash__":1140},"articles\u002Farticles\u002Feveryday-i-learn-string-trim-vs-trimstring.md","Everyday I Learn - String.Trim vs Trim(string)",{"type":8,"value":1096,"toc":1130},[1097,1100,1103,1106,1109,1121,1124,1127],[32,1098,1099],{},"String.Trim method - Removes all occurrences of white space characters from the beginning and end of this instance.",[32,1101,1102],{},"Trim(var) method - returns a string with no leading or trailing spaces",[32,1104,1105],{},"Yes, there is a difference between these.  The String.Trim will remove any non-visible characters such as line feeds and carriage returns.",[32,1107,1108],{},"How I came across this was as a result of an odd exception I am getting from an application.  Randomly the NameValueCollection after a postback will have an appended or prepended line feed.",[32,1110,1111,1112,1114,1115,1117,1118,1120],{},"i.e.",[774,1113],{},"\nhidCustomerID: -1",[774,1116],{},"\nhidCustomerNo: 0",[774,1119],{},"\nhidCurrent: True    hidOrderID: -1",[32,1122,1123],{},"When the code behind tries to ctype(hidCurrent, Boolean) it recieves True or False with additional hidden line feeds.",[32,1125,1126],{},"This is within an ASP.NET 2.x web application.  I have yet to find the source of this problem but I am hoping the String.Trim() will help me out here.",[32,1128,1129],{},"If you have any ideas please let me know what may be going on here.",{"title":11,"searchDepth":12,"depth":12,"links":1131},[],"2015-04-20T08:07:19.2000000-04:00","Learn something everyday","\u002Farticles\u002Fimages\u002Fu1gRsGzBFH.png",{},"\u002Farticles\u002Feveryday-i-learn-string-trim-vs-trimstring",{"title":1094,"description":1133},"articles\u002Feveryday-i-learn-string-trim-vs-trimstring",[18],"dyD86vhVOaZMdPRBPmlEH1iZtcKlN5GvmNPHl8_FRWg",{"id":1142,"title":1143,"author":28,"body":1144,"createdAt":1214,"description":14,"extension":15,"img":1215,"meta":1216,"navigation":19,"path":1217,"seo":1218,"stem":1219,"tags":1220,"updatedAt":1214,"__hash__":1221},"articles\u002Farticles\u002Fstring-literals-and-c.md","String Literals and C#",{"type":8,"value":1145,"toc":1212},[1146,1149,1170,1179,1200,1203],[32,1147,1148],{},"I was looking for some utility that would take a very long string and convert it to vb.net or c# with line continuation(s) characters. String literals to the rescue.  C# supports two forms of string literals: regular string literals and verbatim string literals. ",[32,1150,1151,1152,1158,1159,1165,1166,1169],{},"A ",[146,1153,1154],{},[1155,1156,1157],"u",{},"regular string literal"," consists of zero or more characters enclosed in double quotes, as in ",[810,1160,1161,1162,1161],{},"\"",[810,1163,1164],{},"hello",", and may include both simple escape sequences (such as ",[810,1167,1168],{},"\\t"," for the tab character) and hexadecimal and Unicode escape sequences. ",[32,1171,1172,1173,1175,1176,1178],{},"In c# regular strings can only span multiple lines with syntax similar to the following: string sql = “SELECT customer “ +",[774,1174],{},"\n“FROM customers “ +",[774,1177],{},"\n“WHERE custId=10”;",[32,1180,1151,1181,1186,1187,1190,1191,1194,1195,1199],{},[146,1182,1183],{},[1155,1184,1185],{},"verbatim string literal"," consists of an ",[810,1188,1189],{},"@"," character followed by a double-quote character, zero or more characters, and a closing double-quote character. A simple example is ",[810,1192,1193],{},"@\"hello\"",". In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a ",[1196,1197,1198],"i",{},"quote-escape-sequence",".",[32,1201,1202],{},"In particular, simple escape sequences and hexadecimal and Unicode escape sequences are not processed in verbatim string literals.  The above sample can be replaced with the ‘literal’ designated by the @ symbol as follows:",[32,1204,1205,1206,1208,1209,1211],{},"string sql = @“SELECT",[774,1207],{},"\nFROM customers",[774,1210],{},"\nWHERE custId=10”;",{"title":11,"searchDepth":12,"depth":12,"links":1213},[],"2015-04-20T08:07:18.0100000-04:00","\u002Farticles\u002Fimages\u002FF0VD2LVE2v.png",{},"\u002Farticles\u002Fstring-literals-and-c",{"title":1143,"description":14},"articles\u002Fstring-literals-and-c",[18],"wR7AFv2jyIEaMk54IdB_kd0WIeTKqKzKljWKic55QNQ",{"id":1223,"title":1224,"author":28,"body":1225,"createdAt":1355,"description":14,"extension":15,"img":1352,"meta":1356,"navigation":19,"path":1357,"seo":1358,"stem":1359,"tags":1360,"updatedAt":1355,"__hash__":1361},"articles\u002Farticles\u002Fdesign-guidelines-classes-vs-interfaces.md","Design Guidelines–Classes vs. Interfaces",{"type":8,"value":1226,"toc":1353},[1227,1245,1269,1281,1294,1306,1312,1318,1323,1329,1342,1345,1350],[32,1228,1229,1230,1232,1234,1236,1237,1240,1241,1244],{},"This is 2nd in a series of articles on .NET design practices.  This article concentrates on classes and interfaces and how they differ and how\u002Fwhen to implement.",[774,1231],{},[146,1233],{},[774,1235],{},"\nAn ",[146,1238,1239],{},"interface"," defines the signatures for a set of members that implementers must provide.  Interfaces ",[146,1242,1243],{},"cannot"," provide implementation details for the members.  Interfaces provide definitions for events, indexers, methods and\u002For properties.  Interfaces are inherited by classes and structures which must provide an implementation for each interfaces’ members.  The Interface doesn't actually do anything but only has a signature for interaction with other classes or interfaces.",[32,1246,1247,1248,1251,1252,844,1254,844,1256,1258,1259,844,1261,844,1263,1265,1268],{},"By convention interfaces are prefixed with a capital “I”.  Interfaces differ from abstract classes in that they only define the member definitions (never the implementations).  Interfaces are good ",[146,1249,1250],{},"for designing components that are interchangeable ","as they all expose specific public members in a consistent manner.  This is key to understanding the value of interfaces.  The ability to have a series of components with similar properties and methods (aka. contracts) promotes consistency and information to the developer.",[774,1253],{},[774,1255],{},[774,1257],{},"\nInterfaces may also be inherited by other interfaces and any class or structure that implements an interface much implement all members in an entire interface inheritance chain.  Interfaces in C# are provided as a replacement of multiple inheritance. Because C# does not support multiple inheritance, it was necessary to incorporate some other method so that the class can inherit the behavior of more than one class.",[774,1260],{},[774,1262],{},[774,1264],{},[146,1266,1267],{},"Danger, Danger: ","If the interfaces are poorly designed and have to change (add functionality) after they have been deployed it WILL cause cascading breaks in existing classes that have implemented them.  As such, interfaces need to be carefully designed.  Alternatives to the interface approach is utilizing abstract classes.   Similarly, modifications to abstract classes can have have breaking issues of derived classes if care is not taken.  Interfaces vs. Abstract classes will be covered in a future article but note that both have things we need to watch for when making modifications. ",[32,1270,1271,1272,1274,1275,1277,1278,1280],{},"Interfaces however are contracts that the developer is keenly aware of and as such he\u002Fshe knows that they cannot change and so just the existence of the interface ensures that everyone is aware of how consistent they must be maintained.  In this essence the usage of an interface establishes a consistent contract (methods and properties) that will not be changed.",[774,1273],{},"\nRemember, an interface tells a class that another class implements all the methods contained in an interface, therefore, you do not have to know what type of object it is, only that it implements the interface.  With interfaces we are moving away from considering classes in terms of what they are, and starting to think about them in terms of what they can do.",[774,1276],{},"\nSo, interfaces are good for establishing similarities between unrelated classes without locking in relationships between classes.  As such they declare methods that one or more classes (of different types) are expected to implement.  Interfaces are similar to base classes in that they provide structure to other derived classes and both can be used for polymorphism.",[774,1279],{},"\nInterfaces are different than base classes in that:",[1282,1283,1284,1288,1291],"ul",{},[1285,1286,1287],"li",{},"A class can inherit only one base class, but it can implement many interfaces",[1285,1289,1290],{},"A base class can contain implementation, an interface cannot",[1285,1292,1293],{},"Interfaces can only contain Methods, Properties, Indexers, and Events. They cannot contain fields or constants (which are used for implementation)",[32,1295,473,1296,844,1298,1300,66,1303],{},[774,1297],{},[774,1299],{},[146,1301,1302],{},"Classes vs. Interfaces",[146,1304,1305],{},"Guidelines",[32,1307,1308,1311],{},[146,1309,1310],{},"Classes ","define both member signatures and implementation details for each member. Abstract (MustInherit in Visual Basic) classes can behave like interfaces or regular classes in that they can define members, and they can provide implementation details but are not required to do so. If an abstract class does not provide implementation details, concrete classes that inherit from the abstract class are required to provide the implementation.",[32,1313,1314,1315,1317],{},"While both abstract classes and interfaces support separating contract from implementation, interfaces cannot specify new members in later versions while abstract classes can add members as needed to support additional functionality.",[774,1316],{},"\nDo favor defining classes over interfaces.",[1282,1319,1320],{},[1285,1321,1322],{},"In later versions of your library, you can safely add new members to classes; you cannot add members to interfaces without breaking existing code.",[32,1324,1325,1326,1328],{},"Do use abstract (MustInherit in Visual Basic) classes instead of interfaces to decouple the contract from implementations.",[774,1327],{},"\nDo define an interface if you need to provide a polymorphic hierarchy of value types.",[1282,1330,1331],{},[1285,1332,1333,1334,1338,1339,1341],{},"Value types must inherit from ",[1068,1335,1337],{"href":1336},"http:\u002F\u002Fmsdn.microsoft.com\u002Fen-us\u002Flibrary\u002Fsystem.valuetype.aspx","ValueType",", and can inherit only from ",[1068,1340,1337],{"href":1336},", so they cannot use classes to separate contract and implementation. In this case, you must use an interface if your value types require polymorphic behavior.",[32,1343,1344],{},"Consider defining interfaces to achieve an effect similar to that of multiple inheritance.",[1282,1346,1347],{},[1285,1348,1349],{},"If a type must implement multiple contracts, or the contract is applicable to a wide variety of types, use an interface.",[777,1351],{"style":780,"src":1352,"alt":11},"\u002Farticles\u002Fimages\u002Fsuitcase-bike.jpg",{"title":11,"searchDepth":12,"depth":12,"links":1354},[],"2015-04-20T08:07:16.9200000-04:00",{},"\u002Farticles\u002Fdesign-guidelines-classes-vs-interfaces",{"title":1224,"description":14},"articles\u002Fdesign-guidelines-classes-vs-interfaces",[18],"3GlliBf0u8RxG37mIAwxdeuY3tHvxAAN16QHnerYJrk",1781574758733]