什么 .Net 对象对应于 IronRuby 哈希
我想从 IronRuby 脚本调用 C# 方法,生成 Ruby 哈希值。我尝试了字典,但保持原样。
public Dictionary<string, string> GetHash()
{
Dictionary<string, string> hash = new Dictionary<string, string>();
hash.Add("a", "1");
hash.Add("b", "2");
return hash;
}
我希望能够在我的 IronRuby 脚本中将它用作哈希值,
myHash = scopeObj.GetHash()
myHash.each{ |k,v|
print("#{k}=#{v}")
}
其结果是:
[a, 1]=
[b, 2]=
I want to call a C# method from an IronRuby script that results in a Ruby hash. I tried Dictionary but that stays as is.
public Dictionary<string, string> GetHash()
{
Dictionary<string, string> hash = new Dictionary<string, string>();
hash.Add("a", "1");
hash.Add("b", "2");
return hash;
}
I'd like to be able to use it in my IronRuby script as a hash
myHash = scopeObj.GetHash()
myHash.each{ |k,v|
print("#{k}=#{v}")
}
The results of which are:
[a, 1]=
[b, 2]=
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不会那样工作,因为 .NET 字典中的项目是 KeyValuePair 实例。
您可以很容易地解决这个问题,只需一行转换代码:
It doesn't work like that since the items in a .NET dictionary are KeyValuePair instances.
You can workaround that pretty easily, with a single line of conversion code: