- Home /
how do I use static bool Contains (T[]array, T item); ?
the Scripting API isn't very specific. im doing everything it says, but I get an error:
CS0246: The type or namespace name `T' could not be found. Are you missing a using directive or an assembly reference?
does that help?
I know I used {} ins$$anonymous$$d of ; but if I use ; then it gives me this error:
CS0501: `exampleScript.Contains(T[], T)' must have a body because it is not marked abstract, extern, or partial
ive tried using extern ins$$anonymous$$d of static with a ; on the end, but then I get the error seen in the picture. Or if I give it a body (as seen in the picture) then it still has that same error
I just want it to return true if user can be found in Names
Answer by Yword · Oct 31, 2014 at 08:36 AM
You can try out the implementation as follows:
using UnityEngine;
using System;
using System.Collections;
public class ExampleScript : MonoBehaviour
{
public string[] names;
public string user;
private void Start()
{
// Testing: Call the generic Contains function
Debug.Log(Contains<string>(names, user));
}
public static bool Contains<T>(T[] names, T user)
{
return Array.IndexOf(names, user) != -1;
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to select adjacent cubes along edges? 2 Answers
Array Index Out of Range - Maze Generation Algorithm 1 Answer