IDE0200 recommends change that increases allocation
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**:
Version 17.11.0 Preview 1.0 [34810.211.main]
**Steps to Reproduce**:
```C#
public class C
{
private static readonly Invoker s_invoker = new();
public void M1() => Use(s_invoker.Invoke);
public void M2() => Use(text => s_invoker.Invoke(text));
public void Use(Func func) {}
}
public class Invoker
{
public int Invoke(string text) => 42;
}
```
**Diagnostic Id**:
IDE0200
**Expected Behavior**:
No diagnostic, or at least a different diagnostic code indicating the change will be making the code less efficient.
**Actual Behavior**:
IDE0200 gets raised on M2 and recommends it be changed to the equivalent of M1. But M1 always allocates a new delegate whereas M2 as written above caches the delegate such that ammortized it only ever allocates once.
Contributor guide
Assessment
This issue has not been assessed yet.