Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. public class Class1
  2. {
  3.     private int counter = 0;                    // this variable tracks where in the array we are.
  4.     private int[] numberArray = new int[10];
  5.  
  6.     // this just fills out the number array with 0-9
  7.     public void setup()
  8.     {
  9.         for (int i = 0; i < 10; i++)
  10.         {
  11.             numberArray[i] = i;
  12.         }
  13.     }
  14.  
  15.     // this is where the magic actually happens
  16.     public void add()
  17.     {
  18.         // here is where you would get some user input etc
  19.         int userInput = int.Parse(Console.ReadLine());
  20.        
  21.         // and this is where we use that input.
  22.         numberArray[counter] = userInput;
  23.  
  24.         // and then we increase the counter variable so that it references the next member of the array
  25.         counter++;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement