Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ModifyingOfRefAndValueTypes
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = { 1, 2, 3, 4, 5 };
- int value = 6;
- //Array and value before modification
- Console.Write("array before modification: ");
- PrintArray(array);
- Console.Write("value before modification: ");
- Console.WriteLine(value);
- ModifyArray(array);
- ModifyValue(value);
- Console.Write("array after modification: ");
- PrintArray(array);
- Console.Write("value after modification: ");
- Console.WriteLine(value);
- }
- private static void ModifyValue(int value)
- {
- value += 45;
- }
- private static void ModifyArray(int[] array)
- {
- array[0] = +45;
- }
- private static void PrintArray(int[] array)
- {
- foreach (var item in array)
- {
- Console.Write(item + " ");
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement