0

In mvc, you can pass arguments like so

  new { A = B, C= "D", E ="F", ... }

I'd like to pass arguments like so to my own procedures, looking for links to any samples/tutorial for the same

thanks

Kumar
  • 10,997
  • 13
  • 84
  • 134
  • 2
    I don't understand the downvotes for this question. The author is clearly an inexperienced C# programmer, but the question is valid and makes sense! – kubal5003 Apr 15 '12 at 15:47

3 Answers3

2

It is object initialization check out this MSDN article

Govind Malviya
  • 13,627
  • 17
  • 68
  • 94
1

You should look into anonymous types and reflection in C#.

In short:

  1. Your method will accept an object
  2. You use reflection to see get at the properties of the passed object.
Arjan Einbu
  • 13,543
  • 2
  • 56
  • 59
0

If you're not using ASP.NET MVC then you'll need to use reflection in your method as stated in an answer above, but if you're writing an ASP.NET MVC extension method you can use HtmlHelper method called AnonymousObjectToHtmlAttributes which creates RouteValueDictionary from anonymous object or use RouteValueDictionary constructor that takes anonymous object to initialize its values.

kubal5003
  • 7,186
  • 8
  • 52
  • 90
  • Great, pointed me to the right direction from the answer by jpbochi here http://stackoverflow.com/questions/1619518/a-dictionary-where-value-is-an-anonymous-type-in-c-sharp since that answer is from 2010 was hoping to find something better using expando perhaps – Kumar Apr 15 '12 at 16:08