## 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. # Getting Past the C# List<T> Challange

The code below works fine in the IDE, but will not let me pass the challenge.

Directions: "Create a static method named GetPowersOf2 that returns a list of powers of 2 from 0 to the value passed in. So if 4 was passed in, the function would return { 1, 2, 4, 8, 16 }. The System.Math.Pow method will come in handy."

Error: " Bummer! Does MathHelpers.GetPowersOf2 return List`1?"

Does anyone now what the Code Challenge is looking for (besides what its asking)

Thanks

MathHelpers.cs
```using System.Collections.Generic;
using System;

namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static List<double> GetPowersOf2(int input)
{
var returnList = new List<double>();
for (int i = 0; i < input+1; i++)
{
}
return returnList;

}

}
}
```

The challenge is confusing in that it wants the List returned to the method to be of type int, however Math.Pow() uses type double for its parameters. Your solution above is close, all you have to do is change each instance of List<double> to List<int> and then use typecasting on your Math.Pow() method, as seen below

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

I do not see any issue in the code. But try declaring the List<double> returnList = new List<double>(); instead of var. Also try if the code may be validating for a List of intergers. try converting the power to an integer and then store it to the List of Intergers than double values.

Nice catch! :)

Try using for(int i=0; i <= input; i++)

Actually,

```for (int i = 0; i < input + 1; i++)
```

And

```for (int 1 = 0; i <= input; i++)
```

Are exactly the same. I had the same issue, but managed to pass the challenge by using int for the list type instead of double and casting the returnList to an int,

```returnList.Add((int)Math.Pow(2, i));
```

I'm rather new to C#, but maybe try getting rid of the +1 from this: for (int i = 0; i < input+1; i++)

Good luck! ~Alex

I've also got the same problem and almost identical code. When I compile and run locally, it produces a list of doubles with the correct values, so it seems to be a bug in the challenge. Has anyone reported it yet? Just adding this answer even after 4 months because I had the same issue and came here to see if there was a bug in the task. Lol

Just to cofirm no bug in this task. Although poorly written question as it seems.

This is the complete solution -

```        int num = Convert.ToInt32(userInput);

List <int> numList = new List <int>();

for (int x = 0; x <= num; x++)
{
}
```

return numList;

```using System.Collections.Generic;
using System;

namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static List<int> GetPowersOf2(int input)
{
var returnList = new List<int>();
for(int i = 0; i <= input; i++)
{
}
return returnList;

}

}
}
``` Alternate solution:

```using System.Collections.Generic;
using System;
namespace Treehouse.CodeChallenges
{
public static class MathHelpers
{
public static List<int> GetPowersOf2 (int value)
{
List<int> returnList = new List<int>(value+1);
for (int i = 0 ; i < returnList.Capacity; i++)
{