Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6342715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:17:39+00:00 2026-05-24T20:17:39+00:00

I know that I can declare delegates that have default constant parameters such as:

  • 0

I know that I can declare delegates that have default constant parameters such as:

delegate void MyDelegate(int x, int y = 5);

and then call it anywhere with any method that matches the signature.

Ok, I’ve got LOTS of methods declared like this way:

public Something FirstMethod(float val = 10, int skip = 0){ ... return sth; }
public Something SecondMethod(float val = 20, int skip = 0){ ... return sth; }
public Something ThirdMethod(float val = 5, int skip = 0){ ... return sth; }

… this list goes up all the way down, anyway, they all have that signature structure. The point here is that, they all have floating point argument, that defaults to something different.

Then, I want to create a delegate that will point to one of these methods:

delegate Something ProblematicDelegateType(<<WHAT WILL GO HERE>>);
ProblematicDelegateType myFunc;
if(someValue == someParameter){
    myFunc = FirstMethod;
}else if(...){
    myFunc = SecondMethod;
}else...
...
}

myFunc();
myFunc(skip:100);

I want to be able to call myFunc both parameterless or with the skip parameter. In this part of code, the first parameter, val, is NOT used. (they are used elsewhere).

What will go to the delegate’s argument list? I want to preserve that method’s default val argument, whatever it is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:17:40+00:00Added an answer on May 24, 2026 at 8:17 pm

    If I understand you correctly, your myFunc will leave out the val parameter entirely, always using the default for whichever method you’re ultimately calling, correct?

    If so, this should accomplish what you’re looking for:

    delegate Something ProblematicDelegateType(int skip = 0);
    ProblematicDelegateType myFunc;
    if (someValue == someParameter) {
        myFunc = skip => FirstMethod(skip: skip);
    } else if (...) {
        myFunc = skip => SecondMethod(skip: skip);
    } else ...
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that I can do something like $int = (int)99; //(int) has a
I know that you can use a dummy int parameter on operator++ and operator--
We all know that we can declare multiple variables in a for loop like
I know that we can easily use the objects declare in our appDelegate class
In MIPS, I know that I can declare an array as: list: .space 20
Today I found one interesting thing. I didn't know that one can't declare a
For throwing exceptions I know that you can declare/define the function with the implication
I know that you can declare a C function outside of a class, but
I know that can co-exists with web form no problem as Hanselman mention here
I know that it's a subject that can raise a lot of debate, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.