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

The Archive Base Latest Questions

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

What I want to do is, I want to pass a pointer to a

  • 0

What I want to do is, I want to pass a pointer to a function that may be any type of a variable(int, long, string, even a class I mean I should be able to pass any variable’s pointer). I’m doing this like that

unsafe class whatever
{
    whatever(object* variable)
    {
          this.variable = variable;
    }
}

ERROR IS: Cannot take the address of, get the size of, or declare a pointer to a managed type (‘object’)

Why I want to do is, I will store the variables passed through the constructor and will use their ToString() method, I’m trying to make a class that is for console applications, Refreshing the variables with their updated variables.

If I could do it like that My code will look like that

unsafe class whatever
{
    whatever(object* variable)
    {
        this.variable = variable;
    }

    object* variable;

    public override string ToString()
    {
        return *variable.ToString();
    }
}
  • 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-23T11:15:25+00:00Added an answer on May 23, 2026 at 11:15 am

    Maybe you should pass in a delegate that your class can use to obtain the “object string”.

    class MyFancyClass
    {
        Func<string> getObjectString;
    
        public MyFancyClass(Func<string> getObjectString)
        {
            this.getObjectString = getObjectString;
        }
    
        private MyOtherThread()
        {
            // ...
            string desc = getObjectString();
            // ...
        }
    }
    
    // ...
    long value = 34;
    MyFancyClass fancy = new MyFancyClass(() => value.ToString());
    
    // ...
    value = 88;
    // getObjectString() should now reflect the new value.
    // The variable is captured in the lambdas closure.
    

    Be careful though, because the delegate is called from another thread and simply calling ToString() may not be safe for all objects and require locking. However a delegate allows the caller to do this, depending on the object.

    Pointers will get ugly, require unsafe code and aren’t stable. The garbage collector can move objects around freely, if you don’t explicitly make the pointers fixed. References can’t be stored and you can only pass them around.

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

Sidebar

Related Questions

I need to pass to function pointer to int. Now if I want to
I want to pass in the tType of a class to a function, and
In the parameter's of a function, I want to pass a default argument that
I want to pass an object by smart-pointer reference to a function. The function
Suppose I want to call a function f that asks for a function pointer
I want to pass an array of arbitrary struct pointers and a comparison function
I want pass a class-instace to a method of an other and be sure
I want to pass a parameter into a factory that will be used to
I want to pass an integer value to a form in .Net so that
I want to pass an int list (List) as a declarative property to a

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.