How to pass the action "null"
I have the following function definition
private void DoExport(Action<ColumnView, bool> UpdateColumns)
{
...
}
private void UpdateNonPrintableColumns(ColumnView view, bool visible)
{
...
}
An example of its call:
DoExport(UpdateNonPrintableColumns);
My question is. How to pass action "null"? Is it possible?
eg.DoExport(null); <- Throws exceptionaffairs>
DoExport (null) throws an exception that is thrown when an action is called in the function body
Skip the empty action if you want:
DoExport((x, y) => { })
Secondly, you should look at your code, as you pass null, if that’s fine.
public void X()
{
A(null);
}
public void A(Action<ColumnView, bool> a)
{
if (a != null)
{
a();
}
}
Or according to C # 6 (using the zero propagation operator):
public void A(Action<ColumnView, bool> a)
{
a?.Invoke();
}