Params keyword in C#

Sourav.Kayal
Posted by Sourav.Kayal under C# category on | Points: 40 | Views : 893
using System;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Data.SqlClient;
namespace BlogProject
{

class Program
{

public static void UseParams(params int[] list)
{
for (int i = 0; i < list.Length; i++)
Console.WriteLine(list[i]);
Console.WriteLine();
}

public static void UseParams2(params object[] list)
{
for (int i = 0; i < list.Length; i++)
Console.WriteLine(list[i]);
Console.WriteLine();
}

static void Main(string[] args)
{
UseParams(1, 2, 3);
UseParams2(1, 'a', "test");

int[] myarray = new int[3] { 10, 11, 12 };
UseParams(myarray);
Console.ReadLine();
}
}
}

Comments or Responses

Login to post response