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

The Archive Base Latest Questions

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

If I create a new Class, and in this class I put a property

  • 0

If I create a new Class, and in this class I put a property like so:

public class CurrentDirectory
{
    private string cd;

    public string CurrentDirectory
    {
        get
        {
            return cd;
        }
        set
        {
            cd = value;
        }
    }

I then, at one point in my program, create a new instance of this class like so:

CurrentDirectory myCurrentDirectory = New CurrentDirectory();

I then set a value to CurrentDirectory like so:

myCurrentDirectory.CurrentDirectory = @"C:\MyFiles\Here";

Then, at another point in my program I create another instance of CurrentDirectory and ‘get’ the value of CurrentDirectory like so:

CurrentDirectory myCurrentDirectory1 = new CurrentDirectory();
string putFilesHere = myCurrentDirectory1.CurrentDirectory;

Will this return the value I set earlier or do I need to ‘get’ and ‘set’ my value within the same instance?

Thanks

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

    No, this does not hold values in this way, no more than setting one user’s name to “Heisenburg” affects my name of “Anthony Pegram”. Each instance of the class is a different object, and instance properties and members of one instance do not carry over to other instances.

    User user = new User(); // this is my object!
    user.Name = "Anthony Pegram"; // this is my name! 
    
    User otherUser = new User(); // this is your object!
    otherUser.Name = "Heisenburg"; // this is your name! 
    
    // my object is not your object
    

    If you need to share properties to where some other place sees the same value you set elsewhere, you need to either share the instance, or make the data itself shared via the static keyword on the property.

    class Foo
    {
        public static string Bar { get; set; }
    }
    

    If using statics, the state becomes global, and is not tied to a particular instance. It, in fact, does not need an instance. You would simply access it via the class name directly, not via an object of that class.

    Foo.Bar = "Blah"; // no instance necessary
    string data = Foo.Bar;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I create a class with a property: public class User { private
How can I create a new Exception different from the pre-made types? public class
When I create a new class file in Flex 3 it warns me that
Class someInterface = Class.fromName(some.package.SomeInterface); How do I now create a new class that implements
I want to create a new object using Class::DBI. One of the fields of
I am tryıng to create new object of other class ın a for loop.
I am using the webapplicationbuilder class to create a new web application and have
I am trying to create a generic class which new's up an instance of
Based on constructor of the class. create or destroy new methods. I often requires
When you create an instance of a class with the new operator, memory gets

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.