repl.it
@kironroy/

array_lists

C#

No description

fork
loading
Files
  • main.cs
  • main.exe
  • notes.txt
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;

class MainClass {
 public static void Main(string[] args) {

  Console.WriteLine("---------Arrays below---------");
  Console.WriteLine(); // breakline

  var jennyNumbers = new [] {
   8,
   6,
   7,
   5,
   3,
   0,
   9
  };

  // Length 

  var lengthArr = "Length of array: ";
  var elem = " elements";

  Console.WriteLine(lengthArr + jennyNumbers.Length + elem);

  Console.WriteLine(); // breakline

  // IndexOf() 

  var index = Array.IndexOf(jennyNumbers, 9);

  Console.WriteLine(index);

  Console.WriteLine(); // breakline

  // Clear()

  /* Array.Clear(jennyNumbers, 0, 2); // first 2 elems set to 0

    Console.WriteLine("Clear = first 2 elems set to 0:");
    foreach (var n in jennyNumbers)
      Console.Write(n);

      Console.WriteLine(); // breakline
      Console.WriteLine(); // breakline
  */
  // Copy() 

  int[] jennyTwo = new int[3];
  Array.Copy(jennyNumbers, jennyTwo, 3);
  Console.WriteLine("Copy = elements from first array are copied to second array:");
  foreach(var n in jennyTwo)
  Console.Write(n);

  Console.WriteLine(); // breakline
  Console.WriteLine(); // breakline

  // Sort() 
  Array.Sort(jennyTwo);
  Console.WriteLine("Sort = elements sorted:");
  foreach(var n in jennyTwo)
  Console.Write(n);
  Console.WriteLine(); // breakline

  /////////////////////////////////////////////////////////

  Console.WriteLine("---------Lists below---------");
  Console.WriteLine(); // breakline

  var numbers = new List<int>() { 1, 2, 3, 4 };
  numbers.Add(1);
  numbers.AddRange(new int[3] { 5, 6 ,7 });

 
  foreach (var number in numbers)
    Console.WriteLine(number);

  Console.WriteLine(); // breakline

  Console.WriteLine("Index of 0 is: " + numbers.IndexOf(1)); // 0 is first elem
  Console.WriteLine("Last Index of 0 is: " + numbers.LastIndexOf(1)); // the second occurence of 1

  Console.WriteLine("Total count of elements: " + numbers.Count); 

  Console.WriteLine(); // breakline

// remove all 1s
 
  for ( var i = 0; i < numbers.Count; i++)
  {
    if (numbers[i] == 1)
    numbers.Remove(numbers[i]);
  }
      
  foreach (var number in numbers)
    Console.WriteLine(number);


numbers.Clear();
 Console.WriteLine("Total count of elements: " + numbers.Count); 















 }
}