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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:52:05+00:00 2026-05-27T07:52:05+00:00

I am probably just being thick but I cannot figure out what to do

  • 0

I am probably just being thick but I cannot figure out what to do here….

I have a library I am trying to create that will have a virtual function that the user can use to create a custom error handler to call later in the code. One of the main hiccups I am hitting is that these errors will be stored in a collection for calling randomly.

Here’s some pseudo code

class Error
{
    string Error {get; set;}
    int ErrorCode {get; set;}

    public void ErrorFunction(params obj[] arrParams);
}


class program
{
    List<Error> errorlist = new List<Error>();

    static void Main(string[] args)
    {
         initList();
         errorlist[0].ErrorFunction("Sometext");         
    }

    public void initList()
    {

         Error err = new Error();
         err.ErrorFunction = MyOverloadedError;

         errorlist.add(err);
    }

    public void MyOverloadedError(params obj[] arrObjects)
    {
         Console.WriteLine(arrObjects); 
    }
}

I seem to remember being able to do this simply with a
void* and a call using the addressof for assigning the function to be called.

Like I said perhaps I am being thick, I know that I have to use a delegate, but I cannot figure out how to define a delegate where it exists in an instance of the class and not as a static member of the class.

to reiterate (since I am tired and not sure if I am making this clear or just more confusing) I want to make a member function that can have a custom function assigned to it.

so basically I can do the following

Error myError = new Error();
myError.ErrorFunction = SomeCustomFunction;
...
myError.ErrorFunction("Some Parameters"); //effectively calling some static function elsewhere

Thanks in advance! my brain hurts too much….

  • 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-27T07:52:05+00:00Added an answer on May 27, 2026 at 7:52 am

    Not sure what you want to achieve or whether an event is more appropriate, but here’s your pseude-code, fixed up to be valid, working C# code:

    delegate void ErrorDelegate(params object[] arrParams);
    class Error
    {
        string ErrorText { get; set; }
        int ErrorCode { get; set; }
    
        public ErrorDelegate ErrorFunction;
    }
    
    static class Program
    {
        static List<Error> errorlist = new List<Error>();
    
        static void initList()
        {
    
            Error err = new Error();
            err.ErrorFunction = MyOverloadedError;
    
            errorlist.Add(err);
        }
    
    
        static void MyOverloadedError(params object[] arrObjects)
        {
            Console.WriteLine(arrObjects);
        }
    
        static void Main(string[] args)
        {
            initList();
            errorlist[0].ErrorFunction("Sometext");     
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably very easy and just I'm being thick - I'm trying to
This is probably just me being stupid somehow or the other, but I am
This will probably be just another unsolved thread but i'll fill in some info
I realize that this is probably a very basic question, but I have spent
I realize I'm probably just dumb and missing something big and important, but I
Understanding that I should probably just dig into the source to come up with
I ran into an issue with something that I am probably just overlooking. I
I must say that so far, I've probably just been darn lucky in that
I believe what I'm trying to do is simple enough, so I'm probably just
I'm trying to figure out how to make this hack for attr_accessible to support

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.