问题
Method 1
public List<IndentItems> GetIndentsByStatus(string projectAddress, string jobAddress, string currentStatus,string ddlevent)
{
List<IndentItems> indentItems =null;
indentItems = GetIndentFilledInfo(filterdReports, false,null ,ddlevent);
return indentItems;
}
Method 2
public List<IndentItems> GetIndentFilledInfo(List<SurveyFeedback> surveyFeedbacks, bool hasupdate, string indentType = null,string ddlevent)
{
}
From Method1 I'm calling the second method and in method2 based on EventID
I will get data. But it was showing Compiler Error Message:
CS1737: Optional parameters must appear after all required parameters.
回答1:
You need to move your optional parameters to the end of the parameter list:
from MSDN:
Optional parameters are defined at the end of the parameter list, after any required parameters. If the caller provides an argument for any one of a succession of optional parameters, it must provide arguments for all preceding optional parameters. Comma-separated gaps in the argument list are not supported. For example, in the following code, instance method ExampleMethod is defined with one required and two optional parameters.
public List<IndentItems> GetIndentFilledInfo(
List<SurveyFeedback> surveyFeedbacks,
bool hasupdate,
string ddlevent,
string indentType = null)
More Read Here
回答2:
optional params should be after all of you method params:
public List<IndentItems> GetIndentFilledInfo(
List<SurveyFeedback> surveyFeedbacks,
bool hasupdate,
string ddlevent,
string indentType = null)
{
// Codes here
}
MSDN
来源:https://stackoverflow.com/questions/27316789/optional-parameters-must-appear-after-all-required-parameters-in-c-sharp