Re: Mathlink and C#

*To*: mathgroup at smc.vnet.net*Subject*: [mg46520] Re: [mg46497] Mathlink and C#*From*: Todd Gayley <tgayley at wolfram.com>*Date*: Sun, 22 Feb 2004 11:27:19 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

At 05:53 AM 2/20/2004, Thomas Manz wrote: >Hi! > >Some time ago I programmed a own procedure in C and used it in >Mathematica, what worked very well. >Now I would be interested in using C# but I can´t find a simple example >neither for the Mathematca worksheet (which should be simple?) nor for a >C# source code. I would expect something like adding two numbers, i. e. >calling a procedure "mysum[2,3]" and getting 5. >The examples in the Mathematica installation (changing the process >priority of the Mathkernel.exe) isn´t that what I would call simple!! > >Does anyone have more information or even an example! > >Best regards >Thomas Manz Thomas, If you look in the Help Browser under the Add-ons & Links tab, you will find the .NET/Link User Guide, which contains some simple examples. The example notebooks you found are intended to be more significant "real-world" examples that go beyond the fragments that are used in the User Guide. If you have a C# class "Foo" with a static method like this: public static int mysum(int i, int j) { return i + j; } Here is how you call it from Mathematica. First make sure .NET/Link is loaded and running: <<NETLink` InstallNET[] Now load your assembly and the Foo class: LoadNETAssembly["c:\\path\\to\\fooassembly.dll"] LoadNETType["Foo"] Call the mysum function: Foo`mysum[2, 3] That's it. If the method isn't static, use NETNew to create a new instance of the Foo class, and call the mysum method on the object: foo = NETNew["Foo"]; foo@mysum[2, 3] Todd Gayley Wolfram Research