CSharp Params sample program for finding a minimum number out of a given list
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
paramsexample p = new
paramsexample();
int y = p.findmin(-1, 2, 3);
Console.WriteLine(y);
Console.ReadLine();
}
}
class paramsexample
{
public int findmin(params int[] numbers)
{
int x = numbers[0];
for (int i = 0;
i < numbers.Length; i++)
{
if (numbers[i] < x)
x = numbers[i];
}
return x;
}
}
}
No comments:
Post a Comment