EN
C# / .NET - 'Enumerable' does not exist in the current context error
1 answers
0 points
When I try to use Enumerable.Repeat()
method, I get the following error. How can I fix this?
Error:
xxxxxxxxxx
1
'Enumerable' does not exist in the current context error
My code:
xxxxxxxxxx
1
using System;
2
3
public class TestClass
4
{
5
public static void Main()
6
{
7
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
8
int length = 5;
9
Random random = new Random();
10
11
var result = Enumerable.Repeat(ALPHABET, length)
12
.Select(s => s[random.Next(s.Length)]).ToArray();
13
14
Console.WriteLine(result);
15
}
16
}
1 answer
3 points
You forgot to import System.Linq
namespace.
Your code should look like:
xxxxxxxxxx
1
using System;
2
using System.Linq;
3
4
public class TestClass
5
{
6
public static void Main()
7
{
8
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
9
int length = 5;
10
Random random = new Random();
11
12
var result = Enumerable.Repeat(ALPHABET, length)
13
.Select(s => s[random.Next(s.Length)]).ToArray();
14
15
Console.WriteLine(result);
16
}
17
}
References
0 commentsShow commentsAdd comment