Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am using MVC4, I need to Consume Service which is Created in PHP language.
That Service needs Parameters as of type Associative Array. I know Associate Array is in only PHP.

Associte Array object in PHP

C#
var params = {
    user_auth:{
        user_name:user_name,
        password:password,
        encryption:'PLAIN'
    },
    application: 'SugarCRM RestAPI Example'
};


How can i construct above Equivalent Associative Array object in C# ?
i need to construct it in C# , and then send as parameter for Service.

How can I achieve this ?

Please Help me with some sample Code or share your ideas ?

Thank You
Posted
Updated 28-May-14 4:43am
v2

1 solution

In C#, that is technically not an array. An array is a collection of objects with the same type. What you have there, is an object and C# allows you to create anonymous objects. Like so:

C#
var p = new {
    user_auth = new {
        user_name = "",
        password = "",
        encryption = "PLAIN"
    },
    application = "SugarCRM RestAPI Example"
};


// use it elsewhere like so:
if(p.user_auth.user_name  == ""){

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900