Advertisement
karlakmkj

List - using Range

Nov 27th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;  //add this so as to be able to use List
  3.  
  4. namespace LearnLists
  5. {
  6.   class Program
  7.   {
  8.     static void Main()
  9.     {
  10.       List<double> marathons = new List<double>
  11.       {
  12.         144.07,
  13.         143.12,
  14.         146.73,
  15.         146.33
  16.       };
  17.  
  18.       List <double> topMarathons = marathons.GetRange(0,3); //first int is the index of the first desired element and the second int is the number of elements in the desired range.
  19.  
  20.       foreach(double timing in topMarathons){  //indicate data type for the element variable
  21.         Console.WriteLine(timing);
  22.       }
  23.  
  24.     }
  25.   }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement