Hi,
new to c#
I have a list of numbers List
Phil
Hi,
new to c#
I have a list of numbers List
Phil
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Oct 22, 2013, 5:58 AM
If so, then the following will execute more quickly and require less memory than what you currently have:
Phil HorrocksPosted Oct 22, 2013, 3:15 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Test
{
static void Main()
{
int delta;
List<int> testList = new List<int>();
List<int> maxTimeList = new List<int>();
testList.Add(2223);
testList.Add(2229);
testList.Add(2235);
testList.Add(2240);
testList.Reverse();
int num = 1;
for (int i = 0; i < testList.Count; i++) // Loop through List with for
{
//Console.WriteLine(testList[i]);
if (num >= testList.Count) {
break;
}
else
delta = (testList [i] - testList [num]);
//Console.WriteLine (delta);
num = num +1;
maxTimeList.Add(delta);
}
Console.WriteLine (maxTimeList.Max ());
Console.Read(); // Pause.
}
}
Hardik PatelPosted Oct 21, 2013, 7:37 AM
VulpesPosted Oct 21, 2013, 7:34 AM
Posted Oct 21, 2013, 7:31 AM
using System;
using System.Linq;
namespace Console1
{
class Program
{
static void Main(string[] args)
{
int[] arrayInt = { 23, 25, 29, 32, 34, 37, 40, 43, 46 };
Console.WriteLine(arrayInt.Max());
Console.WriteLine(arrayInt.Min());
Console.WriteLine(arrayInt.Max() - arrayInt.Min());
Console.Read();
}
}
}
Phil HorrocksPosted Oct 21, 2013, 7:26 AM
Hardik PatelPosted Oct 21, 2013, 7:23 AM
Hardik PatelPosted Oct 21, 2013, 7:18 AM
first Use array.sort and then array.reverse
it will give the largest number.