static void Main(string[] args) { // Create simple host environment var host = new DlrHost<IronPythonLanguage>(new IronPythonLanguage()); // Define class host.DefaultScope.Execute("class MathClass(object):\r\n" + "" + " def add(self, x, y):\r\n" + " return x + y\r\n" + "" + " def sub(self, x, y):\r\n" + " return x - y\r\n"); // Use Math-class var cl = new MathClass(host.DefaultScope); // Call c# -> python Console.WriteLine("Add: 5 + 100 = " + cl.Add(5, 100)); Console.WriteLine("Sub: 90 - 14 = " + cl.Sub(90, 40)); Console.ReadLine(); }
static void Main(string[] args) { // Create simple host environment var host = new DlrHost <IronPythonLanguage>(new IronPythonLanguage()); // Define class host.DefaultScope.Execute("class MathClass(object):\r\n" + "" + " def add(self, x, y):\r\n" + " return x + y\r\n" + "" + " def sub(self, x, y):\r\n" + " return x - y\r\n"); // Use Math-class var cl = new MathClass(host.DefaultScope); // Call c# -> python Console.WriteLine("Add: 5 + 100 = " + cl.Add(5, 100)); Console.WriteLine("Sub: 90 - 14 = " + cl.Sub(90, 40)); Console.ReadLine(); }