IronRubyのAC#ilist に文字列を追加するにはどうすればよいですか?
-
27-10-2019 - |
質問
Rubyスクリプトを使用してC#文字列のリストを変更しようとすると、次の例外が得られます。
未処理の例外:System.ArgumentException:値「Scott」はタイプ「System.String」ではなく、この汎用コレクションでは使用できません。
C#
IList<string> names = new List<string>();
names.Add("scott");
names.Add("jason");
ScriptRuntime runtime = IronRuby.Ruby.CreateRuntime();
ScriptEngine engine = runtime.GetEngine("IronRuby");
ScriptScope scope = engine.CreateScope();
scope.SetVariable("names", names);
engine.ExecuteFile("test.rb", scope);
foreach (var name in names)
{
Console.WriteLine(name);
}
ルビー
names.map! { |item| item.capitalize}
解決
追加 to_clr_string
ルビーコードへ:
names.map! { |item| item.capitalize.to_clr_string }
所属していません StackOverflow