[IronPython] Array element access of C# extension.
Haibo Luo
haiboluo at exchange.microsoft.com
Fri Apr 28 03:43:53 CEST 2006
You can try this:
>>> import System
>>> array = System.Array
>>> x = array[float](range(5))
>>> x
System.Double[](0.0, 1.0, 2.0, 3.0, 4.0)
Or
>>> System.Array.CreateInstance(float, 5)
System.Double[](0.0, 0.0, 0.0, 0.0, 0.0)
>>> x = System.Array.CreateInstance(float, 5)
>>> x[0] = 10
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of HEMMI, Shigeru
Sent: Thursday, April 27, 2006 6:29 PM
To: Discussion of IronPython
Subject: [IronPython] Array element access of C# extension.
Hello group,
I wish to access each element value of single-dimension array in C# extension
from IP. For example, a static method foo.goo defined in C# code,
// fooLib.cs
using System;
namespace fooLib
{
public static class foo
{
public static void goo(int n, double[] x, double[] y)
{
for(int i=0; i<n; i++)
{
x[i] = i;
y[i] = 1.0/i;
}
}
}
}
can be accessed from C# main program:
// testing.cs
using System;
using fooLib;
class testing
{
public static void Main()
{
int n = 10;
double [] x = new double[n];
double [] y = new double[n];
foo.goo(n, x, y);
Console.WriteLine("x[9],y[9]="+x[9]+", "+y[9]);
}
}
I struggled to write an IP code similar to testing.cs but not done,
because of Python has no corresponding simple array data type.
Can anybody show me how I can access each element value of C#
extention like fooLib.cs from IP code?
Thanks in advance,
Best regards,
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list