Happiness (param Array)
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace CSharp_Shell
{
public class Program
{
public static void Main()
{
int[] happiness = new int[5] { 100, 40, 70, 80, 20 };//Mine is 100
printArray(happiness);
//
Console.WriteLine("\nAfter incremented by 2");
increase2(ref happiness);
printArray(happiness);
}
//
//
//This method increase the value of each entry by 2
static void increase2(ref int[] happy)
{
int size = happy.Length;
//
for (int i = 0; i < size; i++)
{
happy[i] += 2;
}
}
//
//
//This method used to print all values of array
static void printArray(int[] happy)
{
Console.WriteLine("Happiness");
foreach (int num in happy)
{
Console.WriteLine(num);
}
}
}
}
Comments
Post a Comment