.NET/C# Array Methods in JS

Is it possible to use the .NET system methods for arrays, like IndexOf and FindAll, without invoking them from a C# script? I’ve had good luck accessing the .NET string methods from JS scripts, but the arrays are giving me fits!

Here’s how to call IndexOf and FindAll from Javascript:

function Start()
{
	var something = [1, 2, 4, 8, 16, 32, 64, 128, 256];

	// How to call IndexOf:

	print("Result: " + System.Array.IndexOf(something, 32));

	// How to call FindAll:

	var summary : String;
	var result = System.Array.FindAll(something, GreaterThan20);
	for(var i : int in result)
	{
		summary += i + " ";
	}

	print(summary);
}

// You have to define the predicate for FindAll separately:

function GreaterThan20(value : int)
{
	return (value > 20);
}

I was about to tell you that you couldn’t call generic functions like FindAll from Javascript, but I thought I’d better try it first and, amazingly, it is actually possible! Who knew? :shock:

Hey guys, what is .NET and how does it relate to JavaScript.

N:shock:b

NCarter, you’re my hero! I’d been trying Array.FindAll and knew that I needed that whole System class but didn’t see how to invoke it without being in C#. This is excellent!