Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Collections Lists Lists

Scott Kim
Scott Kim
518 Points

Help needed please! "'List' could not be found" error!

Please help and thanks in advance! Everything looks okay so far, but it keeps giving me the following error:

MathHelpers.cs(5,23): error CS0246: The type or namespace name List' could not be found. Are you missingSystem.Collections.Generic' using directive? Compilation failed: 1 error(s), 0 warnings

MathHelpers.cs
namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static List<int> GetPowersOf2 (int input)
        {    
            List<int> powerfulList = new List<int>();

            for (int i=0; i <= input; i++)
            {

            int GetPowersOf2 = System.Math.Pow(2, i);
            powerfulList.Add(GetPowersOf2);

            }
         return powerfulList;
        }
    }
}

1 Answer

Try adding using System.Collections.Generic; before the class MathHelpers, since List is from that namespace.

Scott Kim
Scott Kim
518 Points

Thanks again JB!! Wasn't sure the details about the System.Collections.Generic and had to explicitly convert System.Math.Pow(2, i) to int (which I wasn't quite getting why; it seems to register it as double?), but ended up going through it. Thank you thank you!