c# Optional Func Parameter -
I have the following function definition in C #:
public static TResult SomeParentFunctionName & lt; TSource, TResult & gt; (TSource SomeValue, & lt; TSource, TResult & gt; ChildFunction1 of the ceremony & lt; TSource, TResult & gt; ChildFunction2 of the ceremony) This function SomeValue According to my business rules, I always ChildFunction1 / Code> is required, but only need to run occasionally to childfun 2 . Can I do an optional parameter for ChildFunction2 ? How do I do this? And how do I know if it has been passed in the option I have considered.
1) I can create two with SomeParentFunctionName , ChildFunction2 and without one 2) I There is an empty ceremony that will just do nothing to transmit -. But it is not that good practice.
Note: Those who want to start yelling on this question, if you can not help, then just do not do it.
Sure, just set to null:
public static TResult SomeParentFunctionName & LT; TSource, TResult & gt; (TSource SomeValue, & lt; TSource, TResult & gt; ChildFunction1 of the ceremony, & lt; TSource, TResult & gt; ChildFunction2 = null of the ceremony) ... if (childfunction 2! = Null) childfunction 2 (); } If you want to pass in the function for ChildFunction2 , then go ahead and do this if you do not want to give anything for this, the function Leave it while calling. It was actually actually calling you -
Comments
Post a Comment