optional named parameters
Download
Skip this Video
Download Presentation
Optional & Named Parameters

Loading in 2 Seconds...

play fullscreen
1 / 6

Optional & Named Parameters - PowerPoint PPT Presentation


  • 104 Views
  • Uploaded on

Optional & Named Parameters. CS3260 Version 1.0. Overview. Parameterless Methods C# 1.0 Paramerterized Methods C # 1.0 Overloaded Methods C # 1.0 Optional Parameters/Arguments Methods C# 4.0 Named Parameters/Arguments C# 4.0. Method Parameters.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Optional & Named Parameters' - galia


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
overview
Overview
  • Parameterless Methods C# 1.0
  • Paramerterized Methods C# 1.0
  • Overloaded Methods C# 1.0
  • Optional Parameters/Arguments Methods C# 4.0
  • Named Parameters/Arguments C# 4.0
method parameters
Method Parameters
  • void DoEveryThing(){ } //void or parameterless
  • void DoEveryThing(int iv, double dv){ } //parameterized
  • void DoEveryThing(double dv, int iv){ } //overloaded
optional parameters
Optional Parameters
  • “Parameters in C# can now be specified as optional by providing a default value for them in a member declaration. When the member is invoked, optional arguments can be omitted. Furthermore, any argument can be passed by parameter name instead of position.” C# 4.0 Specification
  • void DoEveryThing(int iv=100, double dv = 5.5){ }
  • DoEveryThing();
  • DoEveryThing(222);
  • DoEveryThing(333,75.55);
optional arguments
Optional Arguments

“Formal parameters of constructors, methods, indexers and delegate types can be declared optional:

fixed-parameter:attributesoptparameter-modifieropt type identifier default-argumentopt

default-argument:=expression

  • A fixed-parameter with a default-argument is an optional parameter, whereas a fixed-parameter without a default-argument is a required parameter. “
named arguments
Named Arguments
  • “Named and optional parameters are really two distinct features, but are often useful together. Optional parameters allow you to omit arguments to member invocations, whereas named arguments is a way to provide an argument using the name of the corresponding parameter instead of relying on its position in the parameter list.” C# 4.0 Specification
  • void DoEveryThing(dv:44.45); //passing dv by name
  • void DoEveryThing(iv:555); //passing iv by name
  • void DoEveryThing(dv:5.5,iv:66); //reverse order
ad