CodeDocu.com

 

 

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.

Asp.Net C #: Optional parameters in method

 

 

 

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 >

}

 


Software Entwicklung Stuttgart NĂ¼rtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel