#512 – Two Ways to Pass Data to a Method that Takes a Parameter Array

Defining a parameter array using the params keyword allows you to pass a variable number of arguments to a method.

public void PerformCommands(params string[] commands)

You can pass a variable number of arguments to a method that has a parameter array.

            kirby.PerformCommands("Sit", "Stay", "Beg");

You can also just pass an array of the proper type.

            string[] tricks = new string[] {"Roll over", "Weave"};

            kirby.PerformCommands(tricks);
Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: