How do I pass a 'null' action
.net, c#
Solution
Pass in an empty action if you want to:
DoExport((x, y) => { })
Second, you have to review your code, since passing in `null` is perfectly fine.
public void X()
{
A(null);
}
public void A(Action<ColumnView, bool> a)
{
if (a != null)
{
a();
}
}
Or as per C# 6 (using the null-propagation operator):
public void A(Action<ColumnView, bool> a)
{
a?.Invoke();
}
Problem
I have the following function definition ``` private void DoExport(Action<ColumnView, bool> UpdateColumns) { ... } private void UpdateNonPrintableColumns(ColumnView view, bool visible) { ... } ``` Example of it being called: ``` DoExport(UpdateNonPrintableColumns); ``` My question is. How do I pass a 'null' action? Is it even possible? e.g. `DoExport(null); <- Throws exception` DoExport(null) causes an exception to be thrown when the action gets called in the function body