CSharp examples for Custom Type:Method Parameter
Using params with Multiple Data Types
using System;/* w w w . j a va2 s .co m*/ public class Garbage { public static void Print( params object[] args ) { int i = 0; for( i = 0; i < args.Length; i++) { Console.WriteLine("Argument {0} is: {1}", i, args[i]); } } } class MyApp { public static void Main() { long ALong = 1234567890987654321L; decimal ADec = 1234.56M; byte Abyte = 42; string AString = "this is a test"; Console.WriteLine("First call..."); Garbage.Print( 1 ); // pass a simple integer Console.WriteLine("\nSecond call..."); Garbage.Print( ); // pass nothing Console.WriteLine("\nThird call..."); Garbage.Print( ALong, ADec, Abyte, AString ); // Pass lots Console.WriteLine("\nFourth call..."); Garbage.Print( AString, "is cool", '!' ); // more stuff } }