anonymous-objects

Add property to anonymous type after creation

ぐ巨炮叔叔 提交于 2019-11-26 22:20:46
问题 I use an anonymous object to pass my Html Attributes to some helper methods. If the consumer didn't add an ID attribute, I want to add it in my helper method. How can I add an attribute to this anonymous object? 回答1: If you're trying to extend this method: public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues); Although I'm sure Khaja's Object extensions would work, you might get better performance by creating a

What to use: var or object name type? [duplicate]

余生长醉 提交于 2019-11-26 09:25:30
问题 This question already has answers here : Use of var keyword in C# (86 answers) Closed 6 years ago . this is a question that when programming I always wonder: What to use when we are writing code: var myFiles = Directory.GetFiles(fullPath); or string[] myFiles = Directory.GetFiles(fullPath); var is new and is a Implicitly Typed Local Variables , so we can only use locally and it has rules like can\'t be null, etc., but I wonder if we get any advantage of using it \"normally\". The \"normally\"