In python we have a range that can produce for an array with negative integers too.
For example:
In[4]: range(-2, 2+1)
Out[4]: [-2, -1, 0, 1, 2]
Is there an equivalent system in C#; I am aware of IEnumerable method, but upon trying it I get the following output:
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
//Your code goes here
Console.WriteLine("Hello, world!");
int half_window = 2;
var mySeq1 = Enumerable.Range(-2, 2+1).ToArray();
foreach(var item in mySeq1)
Console.Write(item.ToString() + " ");
}
}
}
Produces the output:
Hello, world!
-2 -1 0
Is there already an inbuilt method that I can use to get the python's output ?
The second argument of Enumerable.Range
specifies the count of the elements to be generated, not the stop value.
Console.WriteLine("Hello, world!");
int half_window = 2;
var mySeq1 = Enumerable.Range(-2, 5).ToArray();
// ^
foreach(var item in mySeq1)
Console.Write(item.ToString() + " ");
Output:
Hello, world!
-2 -1 0 1 2
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