I have one function having two fixed arguments. But next arguments are not fixed, there can be two or three or four of them.
It's a runtime arguments so how can I define that function?
My code looks like:
public ObservableCollection<ERCErrors> ErrorCollectionWithValue
(string ErrorDode, int MulCopyNo, dynamic arguments comming it should be 2 or 3)
{
return null;
}
Use a question mark to set an optional parameter in a function in TypeScript, e.g. function sum(a: number, b?: number) {} . If set to optional, the parameter can have a type of undefined or the specified type, because unspecified parameters get the value undefined . Copied!
A parameter wrapped by { } is a named optional parameter. Also, it is necessary for you to use the name of the parameter if you want to pass your argument.
1) params (C# Reference)
public ObservableCollection<ERCErrors>ErrorCollectionWithValue
(string ErrorDode, int MulCopyNo, params object[] args)
{
//...
}
2) Named and Optional Arguments (C# Programming Guide)
public ObservableCollection<ERCErrors> ErrorCollectionWithValue
(string ErrorDode, int MulCopyNo, object arg1 = null, int arg2 = int.MinValue)
{
//...
}
3) And maybe simple method overloading would still suit better, separating method logic to different methods? Under this link you can also find another description of named and optional parameters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With