Search Unity

VS Code: Can I use Linq?

Discussion in 'Scripting' started by AcademyOfFetishes, Jan 21, 2019.

  1. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    I've seen evidence that in Unity projects you can use Linq. E.g.,

    List<int> filteredList = myList.Where( x => x > 7).ToList();


    But, when VS Code auto completes, it doesn't seem to see a Where method on lists. It also doesn't seem to understand the => symbol.

    I have these settings on my project:



    Can I use Linq, and if so, how do I get VS Code to realize that I can?
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Did you put 'using System.Linq;' at the top of your class?
     
    AcademyOfFetishes likes this.
  3. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    That works! In my defense, VS Code didn't suggest that as a possibility and none of the stack overflow questions mentioned it either. Thank you
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    I would think you'd see Quick Fix suggestions for things like this.