Advertisement
Guest User

Modify array in C#

a guest
Oct 17th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MyProject
  4. {
  5.     public class Program
  6.     {
  7.         static void MultiplyBy2(int[] arr) {
  8.             for(int i = 0; i < arr.Length; ++i)
  9.             {
  10.                 arr[i] *=2 ;
  11.             }
  12.         }
  13.         public static void Main()
  14.         {
  15.             int[] arr = new int[]{1, 2, 3, 4, 5};
  16.             MultiplyBy2(arr);
  17.             for(int i = 0; i < arr.Length; ++i)
  18.             {
  19.                 Console.WriteLine(arr[i]);
  20.             }
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement