PC Review


Reply
Thread Tools Rate Thread

Class constructor issue

 
 
james
Guest
Posts: n/a
 
      21st Jul 2011
I have a issue in implementing my objetcs.

Say I have class called Account. And I have required field which is
accountname.

public Account(string accountName)
: this()
{
_accountName = accountName;
}

So say within the application I want to change the accountName of the
account object.

Say I have

Account account = new Account("myaccount");



and in some where else in the program I need to change the
accountName.

How can I do that,
 
Reply With Quote
 
 
 
 
Udo Nesshoever
Guest
Posts: n/a
 
      21st Jul 2011
Hi!

You didn't specify, how _accountName is defined, but I'd suggest to put
a public property around, if you really need to change it.

Cheers,
Nessi

=== original message ===
from: james
date: 2011-07-21 15:01

> I have a issue in implementing my objetcs.
>
> Say I have class called Account. And I have required field which is
> accountname.
>
> public Account(string accountName)
> : this()
> {
> _accountName = accountName;
> }
>
> So say within the application I want to change the accountName of the
> account object.
>
> Say I have
>
> Account account = new Account("myaccount");
>
>
>
> and in some where else in the program I need to change the
> accountName.
>
> How can I do that,

 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      22nd Jul 2011
On 7/21/2011 9:01 AM, james wrote:
> I have a issue in implementing my objetcs.
>
> Say I have class called Account. And I have required field which is
> accountname.
>
> public Account(string accountName)
> : this()
> {
> _accountName = accountName;
> }
>
> So say within the application I want to change the accountName of the
> account object.
>
> Say I have
>
> Account account = new Account("myaccount");
>
>
>
> and in some where else in the program I need to change the
> accountName.
>
> How can I do that,


You need a ref to the object and either a method or a property that
can change the field.

account.AccountName = "Bla bla";

or:

account.ChangeAccountName("Bla bla");

Arne

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make sure this.Test() call base class method in base class constructor Ryan Liu Microsoft C# .NET 2 27th Aug 2006 07:43 PM
Class Constructor!!! Adam Knight Microsoft ASP .NET 1 31st Oct 2005 09:45 AM
InitializeComponent is generating the wrong code for my custom class. Calling it's base class constructor jrhoads23@hotmail.com Microsoft Dot NET Framework Forms 0 1st Feb 2005 07:10 PM
Calling a struct constructor in a class constructor body Karl M Microsoft VC .NET 4 19th Dec 2004 01:21 PM
Initializing base class portion of a derived class in a constructor J.J. Feminella Microsoft C# .NET 2 9th Apr 2004 10:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:16 AM.