Join Gerry O'Brien for an in-depth discussion in this video Solution: Add two numbers with a function, part of Up and Running with C#.
- View Offline
- Exercise Files
In the challenge of round functions we asked you to…create a function that accepts two numbers and adds them together.…We can output that information to the screen as well.…When we create functions they exist within classes.…So, what I'm going to do is, go to the end curly brace of my main method.…Press Enter a couple times, just to provide some white space here.…I'm going to create a function that doesn't return any…values and simply adds two numbers that get passed into it.…Because we're going to call it from a static method, which is…main, this method should also have the static modifier in front of it.…
We said it won't return any values back.…So therefore we, will use the void keyword.…And, because we're going to add two numbers together, we…essentially want to use a name that is explanatory for our function.…Now, because we're adding two numbers together, we can simply use the…name Sum, which would make sense for a summation of two numbers.…Opening up our parenthesis for our function…means that we now have the opportunity…
- Installing C#
- Working with loops
- Controlling program flow
- Using variables
- Building functions
- Creating and instantiating classes
- Catching errors
- Managing resources with the garbage collector
- Building collections
Skill Level Beginner
1. Introducing C#
2. C# Language Elements
3. Object-Oriented Programming in C#
4. Structured Exception Handling
5. Resource Management in C#
6. Extensible Types in C#
7. Windows Apps in C#
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.