C# 3.0 property setter question!

  • Thread starter Thread starter CSharper
  • Start date Start date
C

CSharper

I know you can now define something like the follwing

public string Name{set; get;}

during compiling it will create requested information along with the
private varaible to work with. Here is my question; I have a class
called Person and I want to get the values but not setting the value.

public class Person myPerson;
public Person LocalPerson
{

}

in the main window
....

myPerson = new Person
 
I know you can now define something like the follwing

public string Name{set; get;}

during compiling it will create requested information along with the
private varaible to work with. Here is my question; I have a class
called Person and I want to get the values but not setting the value.

public class Person myPerson;
public Person LocalPerson
{

}

in the main window
...

myPerson = new Person

sorry I didn't complete what I have

public class person myPerson
public Person LocalPerson
{
set { myPerson = value; }
get { return myPerson; }
}

.... in the window construct

myPerson = new Person();
...

my question is how can I avoid using myPerson variable and use the
property setter itself. Trying to avoid one variable...
Thanks,
 
CSharper presented the following explanation :
sorry I didn't complete what I have

public class person myPerson
public Person LocalPerson
{
set { myPerson = value; }
get { return myPerson; }
}

.... in the window construct

myPerson = new Person();
...

my question is how can I avoid using myPerson variable and use the
property setter itself. Trying to avoid one variable...
Thanks,

That automatic property is not limited to "basic types", you can use
that on any type:

public Person LocalPerson { get; set; }

or

public Person LocalPerson { get; private set; }


you still need a
LocalPerson = new Person();
somewhere.

Hans Kesting
 
CSharper presented the following explanation :











That automatic property is not limited to "basic types", you can use
that on any type:

public Person LocalPerson { get; set; }

or

public Person LocalPerson { get; private set; }

you still need a
LocalPerson = new Person();
somewhere.

Hans Kesting- Hide quoted text -

- Show quoted text -

Excellent, thats what I was looking for
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top