Ali*_*Ali 1 .net c# python ironpython
你能否将这个代码从C#转换为Python在IronPython上运行?
我对Python没有任何经验.
using System;
using Baz;
namespace ConsoleApplication
{
class Program
{
static void Main()
{
Portal foo = new Portal("Foo");
Agent bar = new Agent("Bar");
foo.Connect("127.0.0.1", 1234);
foo.Add(bar);
bar.Ready += new Agent.ReadyHandler(bar_Ready);
}
static void bar_Ready(object sender, string msg)
{
Console.WriteLine(msg.body);
}
}
}
Run Code Online (Sandbox Code Playgroud)
实例化不需要类型定义.调用相同的方法,直接分配代理.以前的答案是绝对正确的,你需要一个很多更多的背景,以C#应用程序"转换"到Python; 它不仅仅是语法.
foo = Portal("Foo")
bar = Agent("bar")
foo.Connect("ip", 1234)
foo.Add(bar)
bar.Ready = bar_Ready
def bar_Ready(sender, msg):
print msg.body
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2928 次 |
| 最近记录: |