Code inspection: Immediate delegate invocation
This inspection reports a delegate that is created only to be invoked immediately. The extra delegate creation is unnecessary and makes the code longer and less direct.
using System;
class C
{
void Log()
{
}
void M()
{
new Action(Log)();
}
}
using System;
class C
{
void Log()
{
}
void M()
{
Log();
}
}
This inspection can also report immediately invoked lambdas or anonymous methods when they can be simplified safely.
13 April 2026