Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

 

 

I want to call a method in C #, which I temporarily fill with an optional parameter

 

Solution - an optional parameter in a method is achieved by defining a parameter with the = actual equals sign and a value.

public Task Methode_with_Optional_Parameter(long optParameter = 0)

{..}

 

If you omit the value, then the parameter behaves like a standard parameter, which optionally specifies the default value.

 

 

 

Example:

Calling a log method with a default ID

public async Task add_LogView(long IDUser, long IDNote = 0)

{

    //< Add logtime >

    Note_View_LogModel newLog = new Note_View_LogModel();

    newLog.IDNote = 0;      //0=Liste

    newLog.IDUser = IDUser;

    newLog.dtView = DateTime.Now;

    _dbContext.tbl_Notes_View_Log.Add(newLog);

    await _dbContext.SaveChangesAsync();

    //</ Add logtime >

}

 

Mobile
»
C #: Converting a 2D Object Array to 2D String Array
»
Asp.Net C #: Optional parameters in method
»
Asp.Net C #: Bool zero to bool
»
C#: Add Item to Array or List
»
C#: Split String into single Words String-Array
»
C#: Convert TimeSpan in Units of time, Seconds, Minutes
»
C#: convert var to int.
»
C#: Convert Var to Int
»
C#: line break in the code line new line
»
C#: Short Code in one line: result from if - else- then

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de