Question by
SaintDaveUK · Jun 17, 2016 at 06:01 AM ·
javascriptlistsparametersarguments
How to use an implicit generic list as a parameter?
I am using JavaScript and I want to write a function that can use a generic list of any type as a parameter.
static function ImplicitFunction(myList:List.<T>) {
//code etc
return;
}
How can I go about doing this?
Comment
Answer by phxvyper · Jun 17, 2016 at 10:18 AM
I believe you'd have to in-turn make your function a generic function...
Unfortunately, JavaScript does NOT have this kind of functionality - you have to use C# if you want to use Generics.
public static void ImplicitFunction<T>(List<T> myList) {
// code etc
return; //btw you dont have to return; in void functions/methods
}
Thank you for the help, I'll try this solution out.
I was worried it would be a JS limitation. One more reason to start transitioning to C# I suppose.
Your code returns the following error:
Assets/Standard Assets/Custom/Global.cs(16,48): error CS0246: The type or namespace name `List`1' could not be found. Are you missing a using directive or an assembly reference?
Any ideas on how to fix this?
$$anonymous$$ake sure you're using System.Collections.Generic;
at the top of your Global.cs
Thank you so much, you have helped me out immensely :)