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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Oct 22, 2013, 1:58 AM EDT
If so, then the following will execute more quickly and require less memory than what you currently have:
Hardik PatelRank #4,439 · 343 reputationPosted Oct 21, 2013, 3:18 AM EDT
first Use array.sort and then array.reverse
it will give the largest number.
Hardik PatelRank #4,439 · 343 reputationPosted Oct 21, 2013, 3:23 AM EDT
Phil Horrocks5 reputationPosted Oct 21, 2013, 3:26 AM EDT
Posted Oct 21, 2013, 3:31 AM EDT
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();
}
}
}
VulpesRank #55 · 29.2K reputationPosted Oct 21, 2013, 3:34 AM EDT
Hardik PatelRank #4,439 · 343 reputationPosted Oct 21, 2013, 3:37 AM EDT
Phil Horrocks5 reputationPosted Oct 21, 2013, 11:15 PM EDT
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.
}
}