C#相当于php关联数组 [英] C# equivalent to php associative array

查看:30
本文介绍了C#相当于php关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 php 自定义购物车应用程序.在这个应用程序中,我必须将某些部分与另一个 C#.net 应用程序集成,所以我在 php 购物车中使用了一个 web 服务.在 webservice 的一种方法中,一些值应该作为关联数组传递,如下所示:

I'm customizing a shopping cart application in php. In this application, I have to integrate some parts with another C#.net application, so I'm using a webservice in a php shopping cart. In one method of the webservice, some values should pass as an associative array like this:

$proxy = new SoapClient('www.mywebservice.com?wsdl');
$associative_array= array(
    'abc'=> 1,'def'=>0,'ghi'=>1,'jkl'=>0
    );

$proxy->call($sessionId, 'methodname', array('somevalue', $associative_array));

在 php 中它工作正常...但问题是我在 C#.net 上苦苦挣扎,我怎样才能通过 C#.net 传递关联数组?我是一名 php 程序员,我认为 C#.net 中没有关联数组,有人说可以使用 C# Dictionary 代替它,但这不适用于 webservice 调用.

In php its working fine... but the problem is that I'm struggling with C#.net, how can I pass an associative array with C#.net? I'm a php programmer, I think there's no associative array in C#.net and somebody said that C# Dictionary can be used instead of that, but that's not working with the webservice call.

C# 代码是:

Dictionary<string,string> map=new Dictionary<string,string>();
map.Add("abc","1");
map.Add("def","0");
object st = mgs.call(sessionid, "methodname", new object[] { "somevalue",map  });

谁能给点建议???

推荐答案

我想你想要一个 Dictionary.但我可能是错的.您应该会在调用 Web 服务时看到使用了生成的类.

I think you want a Dictionary<string, int>. But I could be wrong. You should see what the generated class is used when you call the web service.

要调用 Web 服务,请右键单击项目的 References 文件夹.说添加服务引用.

To call the web service, right click the References folder of your project. Say Add Service Reference.

将 WSDL url 放在那里,让它为您生成类.

Put the WSDL url in there and let it generate the classes for you.

这篇关于C#相当于php关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆