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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:10:26+00:00 2026-06-02T08:10:26+00:00

I want to track a variable in my class that was created outside the

  • 0

I want to track a variable in my class that was created outside the scope. In C++ i’d just pass a pointer like this.

class Camera
{
    Player* player;
    Position pos;

    void setFollow(Player* pl) { pl = player; }
    void update() { pos = pl->getPos(); }
}

int Main()
{
    Camera* camera = new Camera();

    Player* player = new Player();

    camera->setFollow(player);
}

In C# I tried to pass by reference but it didnt seem to work.

public class Game1 : Microsoft.Xna.Framework.Game
{
    Camera cam = new Camera();
    Player player = new Player();

    cam.setFollow(ref player);  // <-- by reference
}

This is just a shortened version of my actual code.

Thanks for any help.

EDIT: Thanks to all for the information.

  • 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-02T08:10:27+00:00Added an answer on June 2, 2026 at 8:10 am

    In C#, object (class) variables are implicitly pointers. So, if your class Camera has a field p of type Player, setting cam.p = player in your code would leave both references pointing to the same instance. There’s generally no need to use ref unless you’re passing value types (int, float, structs, etc) by reference.

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

Sidebar

Related Questions

am using Tortoise SVN from few months. I just want to track down what
I want to keep track of a callback method in one of my class
I have created a class that I've been using as the storage for all
I am trying to create a persistent and shared variable that will keep track
i have a function(initialize) inside the a.as File.i want to access the that Variable
I want to create a class that handles Flash-PHP client-server communication. Basically, Flash sends
I've defined a class, and I'd like to have a class method (or variable,
I would like to have a static member variable keep track of the amount
I want to use a static class variable to maintain state of a Playlist
We want to track the time taken by a web service call between 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.