© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
20 replies
popcorn

Delegate function with params

Hello, is it possible to somehow have "named" parameters in the delegate function?
Right now I have:

public delegate bool ValidatorF<T>(params T[] args);

// Usage
public static class IntValidator
{
    public static ValidatorF<int> IsExact = args => args[0] == args[1];
}
public delegate bool ValidatorF<T>(params T[] args);

// Usage
public static class IntValidator
{
    public static ValidatorF<int> IsExact = args => args[0] == args[1];
}


But that way you have to remember that the first argument is the actual number and the second argument is the expected value for example (In this case it doesn't matter, but let's say we have 3+ args..)

My question is:
Is it possible to have the usage like this somehow? Or using some other approach?
 public static ValidatorF<int> IsExact = (val, expected)=> val == expected;
 public static ValidatorF<int> IsExact = (val, expected)=> val == expected;
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Delegate vs lambda function/expression
C#CC# / help
11mo ago
Delegate with Task problem
C#CC# / help
2y ago
Delegate type mismatch
C#CC# / help
3y ago
✅ Get delegate from event
C#CC# / help
3y ago