Функции с массивами - C#
Формулировка задачи:
Как можно сделать в основной программе так, чтобы передавался массив чисел с клавиатуры?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void F(params int[] args)
{
Console.WriteLine(" Количество аргументов: {0}", args.Length);
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine(" \targs[{0}] = {1}", i, args[i]);
}
}
static void Main()
{
Console.Write(" Введите элементы массива ");
int a;
a = Convert.ToInt32(Console.ReadLine());
F(new int[] {1,2,3,4});
Console.ReadLine();
}
}
}Решение задачи: «Функции с массивами»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void F(params int[] args)
{
Console.WriteLine(" Количество аргументов: {0}", args.Length);
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine(" \targs[{0}] = {1}", i, args[i]);
}
}
static void Main()
{
Console.WriteLine(" Введите элементы массива ");
int a,b,c,d,e;
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
c = int.Parse(Console.ReadLine());
d = int.Parse(Console.ReadLine());
e = int.Parse(Console.ReadLine());
F(a,b,c,d,e);
Console.ReadLine();
}
}
}