Chevron Left Icon
Method Calls and Input
Lesson 1 of 2
Chevron Right Icon
  1. 1

    Imagine making a hamburger: 1. Place the bread down 2. Add the burger patty 3. Add the pickles 4. Place the bread on top What if you had to say each step every time you ordered a hamburger? It’s …

  2. 2

    You’ve been using methods since you started learning C#! Commands like […] and […] are methods. Each method has a different behavior: The first method prints something to the console, and…

  3. 3

    Like a math function or a factory machine, a method takes input and returns output. We’ve just seen how input works (arguments). Let’s see how output works. When a method returns a value, it e…

  4. 4

    Up until now, you’ve been calling built-in methods: methods that are available whenever you use C#. Sometimes you need a custom method for your specific program. In that case, you’ll need to define…

  5. 5

    Remember calling methods with arguments, like […] ? Methods that you define can use arguments as well, making them more versatile and useful. While we are defining our method, we don’t know the…

  6. 6

    One thing to watch for with parameters: they can only be used inside their method! […] You’ll see an error like… […] When talking to other developers about this type of issue, you might h…

  7. 7

    To make our functions even more flexible, we can make certain parameters optional. If someone calls your method without all the parameters, the method will assign a default value to those missing…

  8. 8

    Say your method has lots of optional parameters, but you only want to specify one when you call it. In this example, your method has five optional parameters: […] When you call the method, yo…

  9. 9

    Say you want to use […] , a built-in method. You go to the Microsoft documentation to learn how to use it, and find at least 8 di…

  10. 10

    You learned a lot this lesson: congrats on finishing! Here’s what you’ve covered: Call a method with its name and parentheses: […] Store a method’s returned value in a variable: […] * D…

  1. 1

    What’s the outcome of calling a method? Sometimes a message is printed to the console: […] Sometimes a value is returned: […] Sometimes a variable is altered: […] If you don’t underst…

  2. 2

    The basic way to return values from a method is to use a […] statement! (A well-constructed programming language shouldn’t have a lot of surprises.) […] The keyword […] tells the com…

  3. 3

    As we mentioned before, we don’t like surprises — they lead to mistakes. So, when we call a method, we’d like to know what type of value will be returned. This is done in the method definitio…

  4. 4

    A method can only return one value, but sometimes you need to output two pieces of information. For example the […] method tries to parse its input as an integer. If it can, it returns […..

  5. 5

    We can use […] parameters in our own methods as well. In this example, […] converts […] to uppercase and sets a boolean variable to […] : […] * The […] parameter must have …

  6. 6

    As with […] , […] is a very useful keyword, but it can lead to errors if used incorrectly. Here are two common ones: This error means that the […] parameter needs to be assigned a value…

  7. 7

    Congrats on finishing! You can now use and define methods with output. Here’s what else you’ve learned in this lesson: Methods return values with the […] keyword. Every method has a return…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo