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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:14:58+00:00 2026-06-07T07:14:58+00:00

If I had an object of which I only needed access to a particular

  • 0

If I had an object of which I only needed access to a particular part of, should I pass in just that particular part or should I pass the entire object in?

In my case, I’m building a game with C# using XNA and I need access to the “bounds” of the Camera class in “DrawLayer.cs”, a class that draws a single layer (assuming there’s multiple layers due to parallax) of the game onto the screen. The “bounds” of the camera exist as a property below:

    public Rectangle Bounds { get { return onScreenCamera.Bounds; } }

The game is a multiplayer game that has a camera that jumps between players depending on their actions, so “onScreenCamera” references the camera that currently needs to be used. Also, the camera functions differently depending which player type you are, so I made an interface ICameraSetup.cs that the camera I’m discussing implements. Here’s the ICameraSetup interface:

interface ICameraSetup
{
    Vector2 Position { get; }
    Rectangle Bounds { get; }

    void Update(GameTime pGameTime);
}

With DrawLayer.cs, I wanted to write the constructor header like this (note that Rectangle is a struct, which should mean it’s a value-type):

    public DrawLayer(ref Rectangle pBounds)

and then with the constructor call, it was like this:

    new DrawLayer(ref levelState.Camera.Bounds)

This would be passing only the bounds of the camera into DrawLayer.cs, but I seem to be getting this error: “The Property Game.Camera.ICameraSetup.Bounds has no setter.” The issue is, I don’t want the interface to declare a setter for Bounds because the only class that should be able to set bounds is the Camera class and the way Bounds is set is through the private variable in the camera class, mentioned above, called “onScreenCamera”.

But, even if I add Set to the Bounds property, I still get this error at the DrawLayer.cs constructor call: “‘ref’ argument is not classified as a variable.”

Now, one solution that I know works is to pass the entire camera into DrawLayer.cs and use bounds from there, like this:

    public DrawLayer(ICameraSetup pCamera)

then

    new DrawLayer(levelState.Camera)

then use Camera.Bounds, but this seems unnecessary as all I need are the bounds in that class.

Another issue I might be having is with my understanding of pass-by-reference. I understood it to be useful when you need a value-type reference to stay updated with the whatever changes are made to the value outside of the class you passed it into, but I’ve also read that it was the other way around: use it to change a value-type outside of where it’s initially declared and have it stay the same.

So am I making a mistake with my passing-by-reference of the Bounds of the Camera into DrawLayer?

  • 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-07T07:14:59+00:00Added an answer on June 7, 2026 at 7:14 am

    You’re ignoring the first error:

    A property, indexer or dynamic member access may not be passed as an out or ref parameter.

    Additionally, passing an argument by reference in this way means that it can be set, which it cannot because you define no public setter for the Bounds property. So, we have two problems.

    I’m confused; why are you attempting to pass it by reference to begin with? You wish to store a reference to this object so that it can be changed later (FYI: you can’t)? Sounds like a poor design to me to be honest. This doesn’t seem like a performance concern, so I would suggest tweaking your design.

    When you run into things like this which are weird and become clunky/don’t work well, it usually means you have a design problem on your hands. Don’t attempt to fix that by introducing more design problems.

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

Sidebar

Related Questions

I have a simple object called Entry , which until just recently only had
How I can delete an object which I had added before with this code.
I had some code that constructed an object: function gridObjConst(id, itemName, itemPrice, itemListPrice, width,
Initially I had a method in our DL that would take in the object
I have just had a brain block, I have a Deck object and want
I pass a Date object to a method which calls date.getHours() or any other
I just had a question based on MVC model, which I want to utilize
I'm currently building a very bare bones web app, that had the requirement of
I've just finished building a portion of a program which deals with a UI
In a WPF application I had a BackgroundWorker thread creating an object. Let's call

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.