Return a list from a method in C#

Im trying to return a list from a method in C#, however Im getting an error

“the type or namespace name ‘List’ could not be found”

This is the code Im using :

using System.Collections.Generic;

public List findNeighbours()
{
	List<GameObject> localFish = new List<GameObject>();
	foreach(GameObject fish in fishSchool)
	{
		float distance = Vector3.Distance (transform.position, fish.transform.position);
		if (distance <= nDistance) 
		{
			localFish.Add(fish);
		}
	}
	return localFish;
}

Is there a way to return a list from a method in C#?

Thanks!

List is a generic and therefore requires a specification of type. You are missing this in the return portion of your method signatur, this part:

public List findNeighbours()

You need to specify the type like you did in the method. That way the method knows what its returning specifically.

public List<GameObject> findNeighbours()

You need to tell returning type of the List:

 public List<GameObject> findNeighbours()

But you can
yo just need to specify what the list contains

public  List<GameObject> Mylisdt()
    {

        return new List<GameObject>();
    }

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UCList
{
public string UnitName;
public int UnitCount;
}
public class UnitContainers : MonoBehaviour
{
public ListUnitContainList = new List();
void Start()
{

}
public CreateThisUnit(string unit, int count)
{
    UnitContainList = new List<UCList>();
    
    return List<UCList>() UnitContainList;
}

}
Assets/skripts/UnitContainers.cs(21,31): error CS1002: ; expected

what would i need to change?,using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UCList
{
public string UnitName;
public int UnitCount;
}
public class UnitContainers : MonoBehaviour
{
public ListUnitContainList = new List();
void Start()
{

}
public CreateThisUnit(string unit, int count)
{
    UnitContainList = new List<UCList>();
    
    return List<UCList>() UnitContainList;
}

}

UnitContainers.cs(21,31): error CS1002: ; expected
if i type return UnitContainList;
then its missing the return type

i mean i got the return type i got what i want to return why cant i ?