Introduction

Completed

Methods have the ability to perform operations on input. Passing parameters to your methods allows you to perform the method's task with different input values. Using method parameters lets you extend your code while keeping your program organized and readable. If you consider a method to be a black box that accepts input and performs a single task, you can quickly divide a large problem into workable pieces.

Suppose you need to write code that performs the same operation on different sets of input. You might have three different arrays, and need to display the contents of each one. You can create a DisplayArray method that accepts a single array as input and displays the contents. Instead of writing code to display each individual array, you can call the same method and provide the different arrays as input.

Parameters can make your methods more robust while still performing the same general task. In this module, you'll learn more about working with parameters and solidify your understanding of methods.

Learning Objectives

In this module, you will:

  • Learn more about using parameters
  • Understand method scope
  • Understand pass-by-reference and pass-by-value parameter types
  • Learn how to use optional and named arguments

Prerequisites

  • Experience using C# data types including int, string, arrays, and 2D arrays
  • Experience using switch statements, if-else statements, and for-loops
  • Experience using the Random class to generate a random number.
  • Basic understanding of C# methods