[{"data":1,"prerenderedAt":263},["ShallowReactive",2],{"article-anonymous-objects-or-types-net-3-0":3},{"article":4,"tags":91,"previous":92,"next":217},{"id":5,"title":6,"author":7,"body":8,"createdAt":80,"description":81,"extension":82,"img":74,"meta":83,"navigation":84,"path":85,"seo":86,"stem":87,"tags":88,"updatedAt":80,"__hash__":90},"articles\u002Farticles\u002Fanonymous-objects-or-types-net-3-0.md","Anonymous Objects or Types (.NET 3.0+ )","[object Object]",{"type":9,"value":10,"toc":77},"minimark",[11,15,37,40,43,46,65,68],[12,13,14],"p",{},"Details...",[16,17,18,22,25,28,31,34],"ul",{},[19,20,21],"li",{},"an anonymous type declaration begins with the new keyword followed by a member-initializer list in braces {}",[19,23,24],{},"the compiler generates a new class definition that contains the properties specified in the new member-initializer list",[19,26,27],{},"all properties of an anonymous type are public and immutable  * anonymous type properties are read-only (you cannot modify a properties value once the object is created)",[19,29,30],{},"each property's type is inferred from the values assigned to it",[19,32,33],{},"the compiler defines a ToString method that returns comma-separated list of property-name = value pairs",[19,35,36],{},"Equals method compares the properties of two or more anonymous types",[12,38,39],{},"Examples...  \u002F\u002FCreate a 'person' object using an anonymous type",[12,41,42],{},"var bob = new { Name = \"Bob\", Age = 37 };",[12,44,45],{},"bob in this case is the anonymous type, and the types of the properties are inferred by the value assigned.  \u002F\u002Fdisplay information (note here however that the ToString is not required as a ToString method is automatically defined and is the anonymous type)",[12,47,48,49,52,53,55,56,58,59,61,62,64],{},"Console.WriteLine(\"Bob:\" + bob.ToString());",[50,51],"br",{},"\n\u002F\u002Fthe ToString() method would output the following",[50,54],{},"\nBob: { Name = Bob, Age = 37 }",[50,57],{},"\nvar steve = new { Name = \"Steve\", Age = 36 };",[50,60],{},"\n\u002F\u002Fthe compiler is able to recognize the anonymous type for bob and steve are identical and of the same class by the fact that the properties and types were\nidentical for both bob and steve",[50,63],{},"\n\u002F\u002Fthe anonymous type also creates an equals method that is capable of comparing all objects of this anonymous\ntype (so name and age properties will be compared)",[12,66,67],{},"Console.WriteLine(bob.Equals(steve) ? \"equal\" : \"not equal\"));",[12,69,70,71],{},"The output from the is \"not equal\".",[72,73],"img",{"src":74,"alt":75,"style":76},"\u002Farticles\u002Fimages\u002Fanonymous.jpg","","display:none;",{"title":75,"searchDepth":78,"depth":78,"links":79},2,[],"2015-04-20T08:07:17.7300000-04:00","Anonymous types.","md",{},true,"\u002Farticles\u002Fanonymous-objects-or-types-net-3-0",{"title":6,"description":81},"articles\u002Fanonymous-objects-or-types-net-3-0",[89],"NETFeatures","cGVbO2z6ACthfgTvN4W5MWa6AETH2I_6hrC8J6udoNU",[],{"id":93,"title":94,"author":7,"body":95,"createdAt":207,"description":208,"extension":82,"img":209,"meta":210,"navigation":84,"path":211,"seo":212,"stem":213,"tags":214,"updatedAt":207,"__hash__":216},"articles\u002Farticles\u002Fcss-lost.md","CSS Lost, Missing, Absent, Gone after Postback in Asp.NET",{"type":9,"value":96,"toc":205},[97,100,103,106,111,114,117],[12,98,99],{},"I have a generic function in one of my helper libraries that allows me to open a new browser window when a button is selected.  \nThe button posts back to the server runs some code and opens a new window.  \nI often use this sort of thing on a reporting page allowing me to post some search criteria and open a new window (a pdf report).",[12,101,102],{},"I found this type of helper function useful however I found that I was losing my CSS after the postback.",[12,104,105],{},"To avoid losing the css keep the following in mind:",[16,107,108],{},[19,109,110],{},"ensure that your css files are included declarative in your aspx page (not through code behind)",[12,112,113],{},"use Page.ClientScript.RegisterStartupScript(this.GetType(),”name”,script); (Not Response.Write)",[12,115,116],{},"The end helper function looks something like the following:",[118,119,121,122,121,138,145,146,121,157,179,180,179,195,179,202,134],"div",{"style":120},"font-size: 9pt; background: white; color: black; font-family: consolas","   \n",[12,123,125,126,131,135],{"style":124},"margin: 0px","    ",[127,128,130],"span",{"style":129},"color: gray","\u002F\u002F\u002F",[127,132,134],{"style":133},"color: green"," ",[127,136,137],{"style":129},"\u003Csummary>",[12,139,125,140,142],{"style":124},[127,141,130],{"style":129},[127,143,144],{"style":133}," redirect to a new page from codebehind","  \n",[12,147,125,148,150,152,155],{"style":124},[127,149,130],{"style":129},[127,151,134],{"style":133},[127,153,154],{"style":129},"\u003C\u002Fsummary>",[127,156,125],{"style":133},[12,158,125,159,134,163,134,166,169,170,173,174,178],{"style":124},[127,160,162],{"style":161},"color: blue","static",[127,164,165],{"style":161},"public",[127,167,168],{"style":161},"void"," RedirectToNewWindow(",[127,171,172],{"style":161},"string"," url, System.Web.UI.",[127,175,177],{"style":176},"color: #2b91af","Page"," page) {        ","    ",[12,181,182,183,185,186,190,191,194],{"style":124},"        ",[127,184,172],{"style":161}," script = ",[127,187,189],{"style":188},"color: #a31515","\"\u003Cscript>window.open('\""," + url + ",[127,192,193],{"style":188},"\"');\u003C\u002Fscript>\"",";",[12,196,197,198,201],{"style":124},"        page.ClientScript.RegisterStartupScript(page.GetType(), ",[127,199,200],{"style":188},"\"redirectscript\"",",script);        ",[12,203,204],{"style":124},"    }",{"title":75,"searchDepth":78,"depth":78,"links":206},[],"2015-04-20T08:07:17.8100000-04:00","I have a generic function in one of my helper libraries that allows me to open a new browser window when a button is selected.",null,{},"\u002Farticles\u002Fcss-lost",{"title":94,"description":208},"articles\u002Fcss-lost",[215],"aspnet","b2i1IqyW2Q653DvjckNBJxu4yY2Re8ejfAldTtUJY3I",{"id":218,"title":219,"author":7,"body":220,"createdAt":254,"description":255,"extension":82,"img":251,"meta":256,"navigation":84,"path":257,"seo":258,"stem":259,"tags":260,"updatedAt":254,"__hash__":262},"articles\u002Farticles\u002Fauto-implemented-properties-c-net-3-0.md","Auto-Implemented Properties c# .NET 3.0+",{"type":9,"value":221,"toc":252},[222,237,244],[12,223,224,225,227,228,230,231,233,234,236],{},"Instead of the following typical property setter\u002Fgetter  private string courseName;",[50,226],{},"\npubic string CourseName{",[50,229],{},"\n   get { return courseName;}",[50,232],{},"\n   set { courseName = value;}",[50,235],{},"\n}   ",[12,238,239,243],{},[240,241,242],"strong",{},"Auto-Implemented"," property implicitly creates an instance variable for property CourseName",[12,245,246,247,249],{},"public string CourseName {get; set;}      * unable to use the private variable for this property (hidden from developer)     * developer can only reference within the class via CourseName     This is a reasonable approach for quick prototyping of properties only.",[50,248],{},[72,250],{"src":251,"alt":75,"style":76},"\u002Farticles\u002Fimages\u002Fauto.jpg",{"title":75,"searchDepth":78,"depth":78,"links":253},[],"2015-04-20T08:07:17.6400000-04:00","Instead of the following typical property setter\u002Fgetter  private string courseName;\npubic string CourseName{\n   get { return courseName;}\n   set { courseName = value;}\n}   ",{},"\u002Farticles\u002Fauto-implemented-properties-c-net-3-0",{"title":219,"description":255},"articles\u002Fauto-implemented-properties-c-net-3-0",[261],".NET Features","xJ45NgU91LY4F4gvHzxbOH5uIutSNLauJCo5Oy2KAII",1781574771520]