Advertisement
jyoung12387

List - Basic Example

Feb 28th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Program
  5. {
  6.     public static void Main ()
  7.     {
  8.         List<string> dinosaurs = new List<string>();
  9.         //new List of type string called 'dinosaurs' equals a new List of type string
  10.         //in other words, instatiate a new list called 'dinosaurs'
  11.        
  12.         dinosaurs.Add("T-Rex");
  13.         dinosaurs.Add("Raptor");
  14.         dinosaurs.Add("Stegadon");
  15.        
  16.         foreach(string dinosaur in dinosaurs)
  17.             Console.WriteLine(dinosaur);
  18.        
  19.         Console.WriteLine("\n---------------------");
  20.        
  21.         List<string> dogNames = new List<string>() {"Rex", "Buddy"};
  22.        
  23.         foreach(string dogName in dogNames)
  24.             Console.WriteLine(dogName);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement