Hash 哪个.Net对象对应于IronRuby哈希
我想从一个IronRuby脚本调用一个C#方法,该脚本将生成一个Ruby哈希。我试过查这本字典,但还是原样Hash 哪个.Net对象对应于IronRuby哈希,hash,ironruby,Hash,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 h
public Dictionary<string, string> GetHash()
{
Dictionary<string, string> hash = new Dictionary<string, string>();
hash.Add("a", "1");
hash.Add("b", "2");
return hash;
}
结果如下:
[a, 1]=
[b, 2]=
它不是这样工作的,因为.NET字典中的项是KeyValuePair实例 只需一行转换代码,您就可以轻松解决这一问题:
d = scopeObj.get_hash
h = Hash[*d.collect { |x| [x.key,x.value] }.flatten]
h.each { |k,v| puts k,v }
它不是这样工作的,因为.NET字典中的项是KeyValuePair实例 只需一行转换代码,您就可以轻松解决这一问题:
d = scopeObj.get_hash
h = Hash[*d.collect { |x| [x.key,x.value] }.flatten]
h.each { |k,v| puts k,v }