Click here to Skip to main content
16,007,760 members
Home / Discussions / C#
   

C#

 
GeneralRe: Console Application Pin
Nick Parker13-Mar-04 10:45
protectorNick Parker13-Mar-04 10:45 
GeneralRe: Console Application Pin
mil_an13-Mar-04 8:12
mil_an13-Mar-04 8:12 
GeneralRe: Console Application Pin
CWIZO13-Mar-04 8:28
CWIZO13-Mar-04 8:28 
GeneralRe: Console Application Pin
oOomen13-Mar-04 22:11
oOomen13-Mar-04 22:11 
QuestionHow can a class call one of its own accessors? Pin
Adrian Stanley13-Mar-04 3:57
Adrian Stanley13-Mar-04 3:57 
AnswerRe: How can a class call one of its own accessors? Pin
John Fisher13-Mar-04 4:20
John Fisher13-Mar-04 4:20 
AnswerRe: How can a class call one of its own accessors? Pin
Jeff Varszegi13-Mar-04 16:15
professionalJeff Varszegi13-Mar-04 16:15 
AnswerRe: How can a class call one of its own accessors? Pin
Michael Flanakin17-Mar-04 19:19
Michael Flanakin17-Mar-04 19:19 
I know you already got your answer: Yes. But, I wanted to expand upon this a little...

I would say that you always want to access your properties through their accessors. Obviously, you can't always do this (i.e. read-only properties); but, it's an ideal that I suggest you try to adhear to. My reasoning behind this is that you might have business logic tied into your accessor methods that should always be used. You've showed this in your example, but let me show you another:

public class User
{
  private string m_strName;
  private string m_strPassword;

  public User(string name, string password)
  {
    Name = name;
    Password = password;
  }

  public string Password
  {
    get { return m_strPassword; }
    set
    {
      if ( ValidPassword(value) )
        m_strPassword = value;
    }
  }

  ...
}
With this example, I'd have to do the User.ValidPassword(string) check every time I wanted to set the value. Instead, if I keep this logic in the setter, and just plan to always use that, I don't have to worry about it.

Of course, you won't always have special logic to put into your getters and setters. But, it would be better to be in the habbit of using them, so when you need to do it that way, you're not trying to change your ways.

Michael Flanakin
Web Log
GeneralDataGrid Sorting Pin
jazzle13-Mar-04 3:37
jazzle13-Mar-04 3:37 
GeneralRe: DataGrid Sorting Pin
Mazdak13-Mar-04 9:40
Mazdak13-Mar-04 9:40 
GeneralRe: DataGrid Sorting Pin
jazzle13-Mar-04 10:42
jazzle13-Mar-04 10:42 
GeneralRe: DataGrid Sorting Pin
Mazdak13-Mar-04 18:30
Mazdak13-Mar-04 18:30 
GeneralRe: DataGrid Sorting Pin
jazzle14-Mar-04 1:41
jazzle14-Mar-04 1:41 
GeneralRe: DataGrid Sorting Pin
jazzle14-Mar-04 9:52
jazzle14-Mar-04 9:52 
GeneralRe: DataGrid Sorting Pin
Mazdak14-Mar-04 9:57
Mazdak14-Mar-04 9:57 
GeneralRe: DataGrid Sorting Pin
jazzle14-Mar-04 10:07
jazzle14-Mar-04 10:07 
Generalhelp me Pin
vatavua13-Mar-04 3:21
vatavua13-Mar-04 3:21 
GeneralRe: help me Pin
Dave Kreskowiak13-Mar-04 4:26
mveDave Kreskowiak13-Mar-04 4:26 
GeneralRe: help me Pin
Corinna John13-Mar-04 8:18
Corinna John13-Mar-04 8:18 
GeneralRender child controls into memory dc Pin
Mathew Hall13-Mar-04 2:18
Mathew Hall13-Mar-04 2:18 
GeneralBit to Byte and base type size in C# Pin
Tristan Rhodes13-Mar-04 1:25
Tristan Rhodes13-Mar-04 1:25 
GeneralRe: Bit to Byte and base type size in C# Pin
leppie13-Mar-04 3:06
leppie13-Mar-04 3:06 
GeneralRe: Bit to Byte and base type size in C# Pin
Tristan Rhodes13-Mar-04 4:08
Tristan Rhodes13-Mar-04 4:08 
GeneralRe: Bit to Byte and base type size in C# Pin
leppie13-Mar-04 6:50
leppie13-Mar-04 6:50 
GeneralRe: Bit to Byte and base type size in C# Pin
Tristan Rhodes14-Mar-04 0:17
Tristan Rhodes14-Mar-04 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.