Optional named parameters
This presentation is the property of its rightful owner.
Sponsored Links
1 / 6

Optional & Named Parameters PowerPoint PPT Presentation


  • 70 Views
  • Uploaded on
  • Presentation posted in: General

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.

Download Presentation

Optional & Named Parameters

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


Optional named parameters

Optional & Named Parameters

CS3260

Version 1.0


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


  • Login