Advertisement
elena1234

Array - interview question (New Sintax)

May 30th, 2021 (edited)
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Array
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.              int[] array = new int[] { 10, 2, 3, 30, 50, 6, 7, 8 };
  10.             var elements = array[4..5];
  11.  
  12.             foreach (var item in elements)
  13.             {
  14.                 Console.WriteLine(item); // 50
  15.             }
  16.  
  17.             var newElements = array[5..];
  18.             foreach (var item in newElements)
  19.             {
  20.                 Console.WriteLine(item); // 6 7 8
  21.             }
  22.         }
  23.     }
  24. }
  25.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement