Is this a clean and correct way to generate a list of consecutive uints?
The cast looks kind of ugly, but I’m a beginner…might be there is a method without casting around?
public class Test
{
static readonly IEnumerable<uint> AvailableChannels
= (IEnumerable<uint>)Enumerable.Range(1,1000);
}
It’s still a cast though …
EDIT
The
.ToList()is so the full list doesn’t need to be recreated every time you loop over it. (OK, a 1000 uints isn’t much, but it’s the principle of it – if they were classes you would create new ones every time and get unexpected results, like lost changes)EDIT2
The
Cast<uint>()doesn’t work at runtime (“Specified cast is not valid”). Changed to a.Selectto perform the cast.