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开发者_JAVA技巧 parsing strings, since I can't for the life of me do that correctly?
The documentation for SetComplexType is here: http://reference.wolfram.com/mathematica/NETLink/ref/SetComplexType.html. You can also find this by pasting "NETLink/ref/SetComplexType" into the Mathematica documentation center. Both these sources indicate that you must execute Needs["NETLink
]" prior to use in Mathematica.
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()
.
精彩评论