Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Named Arguments

Another feature related to passing arguments to a method is the named argument. Named arguments were added by C# 4.0. As you know, normally, when you pass arguments to a method, the order of the arguments must match the order of the parameters defined by the method. In other words, an argument’s position in the argument list determines to which parameter it is assigned. Named arguments remove this restriction. With a named argument, you specify the name of the parameter to which an argument applies. Using this approach, the order of the arguments is not important. Thus, named arguments are a bit like object initializers described earlier, although the syntax differs.

To specify an argument by name, use this syntax:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial