From the course: Learning C#

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Named and default parameters

Named and default parameters - C# Tutorial

From the course: Learning C#

Named and default parameters

- [Narrator] Functions in C-sharp have some nice convenience features that make them easy to work with while making your code more readable. So let's open up the default params folder in our functions folder. And we're going to take another look at our PrintWithPrefix function from the previous example. So this function takes two arguments. So there's the string to be printed and the prefix that we want to print in front of it. And you can see that all it does is it calls console.writeLine and it prints the prefix, a space and then the string to print out. Now, suppose we don't want there to be any prefix for a particular string we want to print this way. Well, we can call this with an empty string. So for example, I could call this like this PrintWithPrefix and I can pass in hello there as the string and then just pass in an empty string. And that's not very readable and the empty string doesn't really do anything. So…

Contents