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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:54:38+00:00 2026-06-13T01:54:38+00:00

I am trying to solve the following problem Declare a generic delegate type Action

  • 0

I am trying to solve the following problem

Declare a generic delegate type Action that has return type void and takes as argument a T value. This is a generalization of yesterday’s delegate type IntAction.
Declare a class that has a method

static void Perform<T>(Action<T> act, params T[] arr) { ... }

This method should apply the delegate act to every element of the array arr. Use the foreach statement when implementing method Perform<T>.

My code looks like this so far:

namespace CSharpexercices
{
    public delegate void Action<T>(T value);

    public class GenericDelegate
    {
        static void Perform<T>(Action<T> act, params T[] arr)
        {
            foreach (T i in arr)
            {
               act(arr[i]);
            }
        }
    }
}

It’s not working properly and I got lost with the part “this is a generalization of yesterday’s delegate type IntAction.

Could someone help me pretty please 🙂

  • 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-13T01:54:40+00:00Added an answer on June 13, 2026 at 1:54 am

    IntAction is a delegate type (a type that represents a reference to a method, like a function pointer in C++).

    Most likely your instructor declared it as follows:

    public delegate void IntAction(int input);
    

    And as thus it represents a method that takes in an int and returns void. To generalize this, YOUR HOMEWORK asks you to make a generalization of such a delegate. It wants you to create a method that takes an object of ANY TYPE, let’s say type T, and returns void. That’s indeed the delegate System.Action like you used but I think you’re homework asks you to DECLARE that delegate type. This is how you do it (I called the delegate GenericAction and you would use it in exactly the same way you use Action):

    public delegate void GenericAction<T>(T input);
    

    There is a mistake in your foreach loop. You are trying to assign the result of applying the delegate to an element in an array. But the delegate Action returns void!

    To fix this change

    arr [i] =  act (arr[i]);
    

    to

    act (i); //you can't use the result of applying act to i (because it's void) so just leave it.
    

    Feel free to modify your question or comment if you need more clarification.

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

Sidebar

Related Questions

I'm trying to solve the following problem in Redis. I have a list that
I'm trying to solve the following problem: I have a download button that when
Trying to solve this problem: I have the following set of divs that when
I'm learning C# and trying to solve the following problem: Return the longest subarray
I am trying to solve the following problem with Puppet: I have multiple nodes.
I am trying to solve the following problem. Lets say you have the the
I am trying to solve Project Euler problem in Clojure using recursion. The following
I have the following cyclic dependency problem I am trying to solve: typedef std::map<int,
I'm trying to solve the following problem: Say I have a Python script (let's
I'm trying to solve the following problem: Given an input of, say, 0000000000000000 0011111111110000

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.