Class2.cs 875 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Library6Properties
  7. {
  8. internal class Class2
  9. {
  10. int[] numbers = new int[0];
  11. Random rand = new Random();
  12. public Class2(int n)
  13. {
  14. Array.Resize(ref numbers, n);
  15. Console.Write("Массив: ");
  16. for (int i = 0; i < n; i++)
  17. {
  18. numbers[i] = rand.Next(101); //от 1 до 100
  19. Console.Write(numbers[i] + " ");
  20. }
  21. Console.WriteLine();
  22. }
  23. public int Sum
  24. {
  25. get
  26. {
  27. int sum = 0;
  28. foreach (int number in numbers)
  29. {
  30. sum += number;
  31. }
  32. return sum;
  33. }
  34. }
  35. }
  36. }