Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!