Undefined error when getting a .NET classes List member

Jul 22, 2012 at 5:42 AM
Edited Jul 22, 2012 at 5:42 AM

I'm trying a simple test but repeatedly getting undefined errors.

public class Foo
  �public IList<int> testy = new List<int>() { 0,1,2,3};
void Test()


JavascriptContext context = new JavascriptContext()

context.SetParameter("console", �new Foo()�);

context.Run(@"�var closer = console.testy[1]; �console.Print ('answer: '+closer);




Does anyone know why 'closer' is undefined ?

Jul 22, 2012 at 11:30 PM

I cannot remember whether generic indexing works, but arrays should.  Try var closer = console.ToArray()[1].  Of course the undefined error could also be occurring because you don't have a Print() method.

Jul 23, 2012 at 12:21 AM
Edited Jul 23, 2012 at 1:26 AM

Thanks Oliver,

I have a Print method, I just wrote some example code in my post to illustrate the error.

I tried it with:  int [] testy = new int [] {1,2,3,4};

but it still said it was undefined.


How would you get any array index to work from C# to JS ?