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

  • SEARCH
  • Home
  • 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 6118191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:24:29+00:00 2026-05-23T15:24:29+00:00

I have a user defined class that I want to create a public List

  • 0

I have a user defined class that I want to create a public List as part of. I want the List to be a List of delegate functions that I can add to and set each List Member to a delegate function. I want this list of functions to be part of the class I instantiate, so it follows the instance of the class as I pass it to other functions. I need the ability to call the delegated functions via a foreach loop, so it also has to be IEnumberable.

I’ve been trying for several hours, what I have may or may not do part of the job. When it started looking like I needed to write my own IEnumberation routines for the custom List, I realize I was in way over my head and came here.

This is the code I have:

    public delegate List<ChartTestModel> MyDelegate<T>(T i);
    public class DelegateList<T> 
    {
        public void Add(MyDelegate<T> del)
        {
            imp.Add(del);
        }

        public void CallDelegates(T k)
        {
            foreach (MyDelegate<T> del in imp)
            {
                del(k);
            }
        }
        private List<MyDelegate<T>> imp = new List<MyDelegate<T>>();

    }

I don’t even know if this does what I want it to or not. I know I can’t ForEach through it, though. It’s written entirely from pieced together code from looking on Google. I barely understand what it’s supposed to do.

  • 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-23T15:24:29+00:00Added an answer on May 23, 2026 at 3:24 pm

    IEnumerable<T> is simple to implement, particularly when you have a collection as a member of the class. All you need to do is define appropriate GetEnumerator methods, and the easiest thing to do is return the enumerator of the underlying collection.

    class YourClass : IEnumerable<SomeClass>
    {
        List<SomeClass> list = ...
    
        public IEnumerator<SomeClass> GetEnumerator() 
        {
            return list.GetEnumerator();
        }
    
        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator(); 
        }
    }
    

    Here, you implement methods for implicitly for IEnumerable<T> and explicitly for IEnumerable. (You have to implement both as IEnumerable<T> inherits IEnumerable.)

    For your specific class, you might have

    public class DelegateList<T> : IEnumerable<MyDelegate<T>>
    {
        // ...other class details 
    
        private List<MyDelegate<T>> imp = new List<MyDelegate<T>>();
    
        public IEnumerator<MyDelegate<T>> GetEnumerator()
        {
            return imp.GetEnumerator();
        }
    
        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ask a question about Java. I have a user-defined object class,
I have a List of Tasks that a user can preform. Each one will
Suppose I have an array of a objects of user defined class. Wanted to
I have some logic, which defines and uses some user-defined types, like these: class
So I have the following user defined type in my oracle database: CREATE OR
I have a user that want to be able to select a textbox and
hi i defined one class to create cookie by received parameter's from user. when
I'm currently writing a serialization module in Python that can serialize user defined classes.
I have a set of custom data types that can be used to manipulate
I have defined an object that has several attribute.. class thing(object): def __init__(self, type,

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.