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:
'Enumerable' does not exist in the current context error
My code:
using System;
public class TestClass
{
public static void Main()
{
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int length = 5;
Random random = new Random();
var result = Enumerable.Repeat(ALPHABET, length)
.Select(s => s[random.Next(s.Length)]).ToArray();
Console.WriteLine(result);
}
}
1 answer
3
points
You forgot to import System.Linq
namespace.
Your code should look like:
using System;
using System.Linq;
public class TestClass
{
public static void Main()
{
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int length = 5;
Random random = new Random();
var result = Enumerable.Repeat(ALPHABET, length)
.Select(s => s[random.Next(s.Length)]).ToArray();
Console.WriteLine(result);
}
}
References
0 comments
Add comment