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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:39:05+00:00 2026-05-31T04:39:05+00:00

I am new in C#. I am from Java world. So I am confused

  • 0

I am new in C#. I am from Java world. So I am confused with the following code:

    class A
    {
        private PointF point;

        public A(PointF point)
        {
            this.point = point;
        }

        public PointF Position
        {
            get { return point; }
        }
    }

I want to change X-coordinate of the position property, so I perform:

        A a = new A(new PointF(1,2));
        PointF p = a.Position;
        p.X = 100;
        Console.WriteLine(a.Position.X); // <--- I have 1 here!

I wonder why the output is NOT 100? As I have understand I have received reference on private field with Position property. Am I right?

Can I change property without adding set-property and propagating Position with new PointF object?

  • 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-31T04:39:07+00:00Added an answer on May 31, 2026 at 4:39 am

    No; PointF is a struct, so it has copy semantics and is not an object; as soon as you’ve obtained it – it is a separate and isolated copy (unless you’re using something like ref/out, which is … more subtle). The struct is actually copied multiple times in your example.

    By the way, a consequence of this is that it is actually a very bad idea to have mutable structs – so in most cases you should avoid the scenario where you can say:

    p.X = 100;
    

    since that causes more confusion than it helps. In particular the following is completely invalid:

    a.Position.X = 100; // won't even compile
    

    (here the compile is spotting that you are changing a copy of the struct that only exists during the mutation itself, which means your change goes nowhere, and is almost certainly a bug)

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

Sidebar

Related Questions

I'm brand new to java, coming from a ruby world. One thing I love
I am new to coding in Objective-C, but am coming from the Java world
My code: import java.awt.Robot; import java.awt.event.KeyEvent; import java.util.Scanner; public class main { public static
pseudo code to explain my self better. I'm learning Java at this point in
I'm new to java world from C++ background. I'd like to port some C++
I transitioned from Java 1.4(previous company) to Java 1.6 (new company). What I have
Note: I'm relatively new to Objective-C and am coming from Java and PHP. Could
I'm very new to Python (I'm coming from a JAVA background) and I'm wondering
I'm developer moving from C# to Java. Heard about new ASP net feature. <%:
I'm a relatively new Java programmer coming from C++/STL, and am looking for 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.