I have a space separated list of int like below:
1 -2 3 1 -8 3 -2 5
I need an absolute sum of a specific range of that list i.e. from 4th index to 6th index. The result will be 10(from abs(-8-2)).
I can get the perfect result by using below code:
List<int> _subList = new List<int>();
string _input = Console.ReadLine();
List<int> _list = _input.Split(' ').Select(n => Convert.ToInt32(n)).ToList<int>();
var k =Math.Abs(_list.GetRange(3, 3).Where(x=>x<0).Sum());
Console.WriteLine(k);
But is there any way to do it without using Linq?