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 6772271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:31:49+00:00 2026-05-26T15:31:49+00:00

I need explanations.. why the following code give an: Parameter count mismatch ? C#

  • 0

I need explanations.. why the following code give an: Parameter count mismatch ?

C# Code:

//... 
public delegate int FindInRichTextBoxMethod(RichTextBox rtx, string target, int index);
 public int FindInRichTextBox(RichTextBox rtx, string target, int index)
    {
        return rtx.Find(target, index, RichTextBoxFinds.None);
    }
// ... 
int start; 
string tempState = "foo";

if (lista.InvokeRequired) {
  object find = Invoke((FindInRichTextBoxMethod)delegate
                            {
                                return FindInRichTextBox(list, tempState, len);
                            });  

                            start = (int)find;
} else {

      start = FindInRichTextBox(list, tempState, len);
 }

Thanks in advance.

  • 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-26T15:31:49+00:00Added an answer on May 26, 2026 at 3:31 pm

    The arguments to Invoke() include a delegate, and the arguments passed to that delegate. You’re attempting to pass a FindInRichTextBoxMethod delegate, but that delegate type takes three arguments. You need to:

    1. construct a delegate with your FindInRichTextBox method, and then
    2. pass in the parameters to that delegate.

    Something like this:

    var finder = new FindInRichTextBoxMethod(FindInRichTextBox);
    object find = Invoke(finder, new object[] { list, tempState, len }); 
    

    Another route is to pass in a closure, sort of like you’re attempting in your sample. In your case the error is due to the cast to a FindInRichTextBoxMethod, so the Invoke is expecting arguments. Instead, you could ignore the cast and pass in an anonymous delegate like this:

    var find = Invoke(delegate { return FindInRichTextBox(list, tempState, len); });
    

    This won’t work, though, because the compiler can’t determine exactly what you want to do with that anonymous delegate. Similarly, a lambda can’t be automatically converted either:

    var find = Invoke(() => FindInRichTextBox(list, tempState, len));
    

    To see why and how to fix the problem, read Why must a lambda expression be cast when supplied as a plain Delegate parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code Snippet Form form2 = new Form(); test(form2); form2.Show(); public void
I need a detailed explanation of the following code line-by-line and how the flow
Need a function that takes a character as a parameter and returns true if
Need to locate the following pattern: The letter I followed by a space then
I have the following code: FROM CTE_Order cte INNER JOIN tblOrders o ON cte.OrderId
Im working with the following code; <a href=\#\ onClick=\if($(this).next('div').css('display') == 'none') { $(this).next('div').show('fast'); }
The following code is pretty self-explanatory and my question is very simple : Why
Regarding the following code: update: (thank you DGM and The Tin Man for recomendation
Can anyone figure out a nice way to get the following code to work?
I need to catch the following tags + content in html source of the

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.