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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:46:12+00:00 2026-06-03T18:46:12+00:00

I have two classes, first: public class A { public delegate void Function(); public

  • 0

I have two classes, first:

    public class A
    {
        public delegate void Function();

        public string name;
        public Function function;

        public A(string name, Function function)
        {
            this.name = name;
            this.function = function;
        }
    }

And in second:

    public class B
    {
        public delegate void Function();
        List<A> ListA;

        // somewhere in function
        void F()
        {
            ListA[i].function();
        }
        // ---

        public void AddA(string name, Function function)
        {
            ListA.Add(new A(name, function)); // error here
        }
    }

It throws these errors:

Error   2   Argument 2: cannot convert from 'App.B.Function' to 'App.A.Function'
Error   1   The best overloaded method match for 'App.A.A(string, App.A.Function)' has some invalid arguments

How to solve this?

  • 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-06-03T18:46:13+00:00Added an answer on June 3, 2026 at 6:46 pm

    You have declared Function delegate twice, one inside class A and one inside B.
    So they’re two different types, one called App.B.Function and the other called App.A.Function.

    If you want to share this delegate with both the classes, just declare it once and out of the scope of the classes (i.e. in the assembly scope) e.g.:

    public delegate void Function();
    
    public class A
    {
        public string name;
        ...
    }
    
    public class B
    {
        List<A> ListA;
        ...
    }
    

    However, in the System namespace exist a certain number of generic delegates that can be used to represent various functions. Have a look at System.Action<> and System.Func<> types.

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

Sidebar

Related Questions

my code is like this: i have two classes first class: public class Box<E>
I have two classes : import android.cla; public class CW { public static void
I have two classes Car and Drivers : public class Car { public string
I have two simple classes generated by code first. public class Company { public
I have two connected classes defined like this: [ActiveRecord] public class Store : ActiveRecordBase<Store>
I have two classes like so: public class SentEmailAttachment : ISentEmailAttachment { public SentEmailAttachment();
Let's say I have two classes. Each class has one parameter. Parameter of first
I have two entity classes: public class Invoice { public int ID { get;
Suppose that I have two classes, first a class without any properties, fields or
I have these two entities. One for Employees: [Table(Name = Employees)] public class Employee

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.