I'm looking for an ultra-easy way to generate a list of numbers, 1-200. (it can be a List, Array, Enumerable... I don't really care about the specific type)
Apparently .Net 4.0 has a Sequence.Range(min,max) method. But I'm currently on .Net 3.5.
Here is a sample usage, of what I'm after, shown with Sequence.Range.
public void ShowOutput(Sequence.Range(1,200));
For the moment, I need consequitive numbers 1-200. In future iterations, I may need arbitrary lists of numbers, so I'm trying to keep the design flexible.
Perhaps there is a good LINQ solution? Any other ideas?
Types of sequence modelsSequence-to-one: In sequence-to-one sequence model, the input data is sequence and output data is non sequence. Sequence-to-sequence: In sequence-to-sequence sequence model, the input data is sequence and output data is sequence.
A Seq2Seq model is a model that takes a sequence of items (words, letters, time series, etc) and outputs another sequence of items. Seq2Seq Model. In the case of Neural Machine Translation, the input is a series of words, and the output is the translated series of words.
SEquence generation tasks aim at generating a target. sequence conditioning on a source input. Standard se- quence generation tasks include neural machine transla- tion [1], [2], image captioning [3], and automatic speech.
Sequence to Sequence (often abbreviated to seq2seq) models is a special class of Recurrent Neural Network architectures that we typically use (but not restricted) to solve complex Language problems like Machine Translation, Question Answering, creating Chatbots, Text Summarization, etc.
.NET 3,5 has Range
too. It's actually Enumerable.Range
and returns IEnumerable<int>
.
The page you linked to is very much out of date - it's talking about 3 as a "future version" and the Enumerable
static class was called Sequence
at one point prior to release.
If you wanted to implement it yourself in C# 2 or later, it's easy - here's one:
IEnumerable<int> Range(int count)
{
for (int n = 0; n < count; n++)
yield return n;
}
You can easily write other methods that further filter lists:
IEnumerable<int> Double(IEnumerable<int> source)
{
foreach (int n in source)
yield return n * 2;
}
But as you have 3.5, you can use the extension methods in System.Linq.Enumerable
to do this:
var evens = Enumerable.Range(0, someLimit).Select(n => n * 2);
var r = Enumerable.Range( 1, 200 );
Check out System.Linq.Enumerable.Range.
Regarding the second part of your question, what do you mean by "arbitrary lists"? If you can define a function from an int
to the new values, you can use the result of Range with other LINQ methods:
var squares = from i in Enumerable.Range(1, 200)
select i * i;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With