Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static LINQ expression throws "Type C+<>c has a static constructor" #1347

Open
znakeeye opened this issue Oct 25, 2024 · 1 comment
Open

Comments

@znakeeye
Copy link

Maybe same as those other static related issues, but here I don't see a constructor... Should be fairly easy to support this?

using System.Linq;
using System.Collections.Generic;

public class C {
    public void M() {
        List<string> list = [];        
        var a = list.Select(static s=> s.Length < 10).ToList();
    }
}
@KeterSCP
Copy link

If you look at the Roslyn-generated code, you can see that there is a static object for the closure that is being initialized. So static constructor is automatically generated for it. IL output confirms this:

// Methods
.method private hidebysig specialname rtspecialname static
    void .cctor () cil managed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants