Search code examples
c#.netwolfram-mathematicamathlink

Setting ComplexType in MathLink


I have another one. I tried to use ml.ComplexType = System.Type.GetType("Complex"); in C# with the Mathematica MathLink, but when I tried to read the numbers with GetComplexArray, it threw an exception stating that I must use the method IMathLink.SetComplexType(), which does not appear to exist.

Is there any way to do this without parsing strings, since I can't for the life of me do that correctly?


Solution

  • For anyone else's reference, I discovered the answer to this one on my own.

    What you do is create a dummy instance of any class that has the necessary properties/methods (such as System.Numerics.Complex), here named myVar. Now assuming ml is an instance of IKernelLink, call

    ml.ComplexType = myVar.GetType();
    

    You can then use ml.GetComplex() or ml.GetComplexArray().