Free Code Snippets in C#, Net Framework, Office 365, ASP.Net,WPF, Visual Studio, SQL Server, Antivirus free
#

 

 

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
»
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
»
How may you replace the word: this in a global static method?

.

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