课程: Learning C#

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Named and default parameters

Named and default parameters - C#教程

课程: 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…

内容