Click here to Skip to main content
15,914,010 members
Home / Discussions / C#
   

C#

 
GeneralRe: Creat New Security Group At AD Pin
Shameel27-Jul-11 1:52
professionalShameel27-Jul-11 1:52 
AnswerRe: Creat New Security Group At AD Pin
Dave Kreskowiak26-Jul-11 1:53
mveDave Kreskowiak26-Jul-11 1:53 
GeneralRe: Creat New Security Group At AD Pin
treuveni26-Jul-11 4:57
treuveni26-Jul-11 4:57 
QuestionStrange Syntax- public string NewPassword { get; set; }and more Pin
Bram van Kampen25-Jul-11 15:33
Bram van Kampen25-Jul-11 15:33 
AnswerRe: Strange Syntax- public string NewPassword { get; set; }and more Pin
PIEBALDconsult25-Jul-11 16:06
mvePIEBALDconsult25-Jul-11 16:06 
AnswerRe: Strange Syntax- public string NewPassword { get; set; }and more Pin
Mark Salsbery25-Jul-11 17:44
Mark Salsbery25-Jul-11 17:44 
AnswerRe: Strange Syntax- public string NewPassword { get; set; }and more Pin
Matt Meyer26-Jul-11 5:30
Matt Meyer26-Jul-11 5:30 
AnswerRe: Strange Syntax- public string NewPassword { get; set; }and more [modified] Pin
Herboren29-Jul-11 11:10
Herboren29-Jul-11 11:10 
I myself and still learning classes in c# 3.0 and I have finally understood the getters and setters to a certain extent.

First you must have an attribute set as private and within its own class. That means that no other method outside of its object can directly change the attribute.

You attribute:
C#
class GetPassword
    {
        private string _NewPassword; //This cannot be changed by any method outside the class 'GetPassword'

        public string NewPassword //However this class can change the value of the private attribute
        {
             get{return this._NewPassword ;} // get meaning return the newly stored string held in the private variable above, this is usually the last thing return  when called outside of the class 'GetPassword'
             set{this._NewPassword = value ;}// This sets the new password or creates the new string before the actual value is returned or called from outside the class 'GetPassword'
        }
    }
private string _NewPassword;


Now outside the class in our main form:

C#
private void button2_Click(object sender, EventArgs e)
       {
           GetPassword setPassword = new GetPassword(); // Allocate memory space for the object
           setPassword.NewPassword = tbSetPassword.Text; // the '= implies we want to 'set the new property of the attribute
           MessageBox.Show(setPassword.NewPassword); // but in this statement we are not really asking to set any properties, yet we only want to 'return' the value that has already been set above ^ which should then give us what we typed into the password box.
       }


Remember when an attribute is set to private in a class, it can not be directly accessed and change by a method outside of the class, so instead the method out side the class 'GetPassword' located in 'Form1' has to access a 'public' method within the class 'GetPassword'. In order to make the change to the private variable. In other words the public string 'NewPassword{}' in 'GetPassword' class, is the public method in this class that can access the private member.

Inside this 'NewPassword{get; set}' method we used the private variable 'this._NewPassword' so this implies and shows the attribute, only this method has access, no other methods. so our method:

C#
setPassword.NewPassword = tbSetPassword.Text;


is actually setting the private member '_NewPassword' by using:

C#
set{this._NewPassword = value ;}


and the button method statement:

C#
MessageBox.Show(setPassword.NewPassword);


Is actually returning the private members '_NewPassword' that had just been set by the user clicking on the button:

C#
get{return this._NewPassword ;}


Sorry if it seems like gibberish but just got off work and trying to leave the building.

modified on Friday, July 29, 2011 5:20 PM

GeneralHello all people, Pin
electrician_man25-Jul-11 6:11
electrician_man25-Jul-11 6:11 
GeneralRe: Hello all people, Pin
David198725-Jul-11 6:14
David198725-Jul-11 6:14 
GeneralRe: Hello all people, Pin
DaveyM6925-Jul-11 8:30
professionalDaveyM6925-Jul-11 8:30 
Questiondata filter options for grid Pin
dessiymartin24-Jul-11 23:51
dessiymartin24-Jul-11 23:51 
AnswerRe: data filter options for grid Pin
Dave Kreskowiak25-Jul-11 1:49
mveDave Kreskowiak25-Jul-11 1:49 
AnswerRe: data filter options for grid Pin
PIEBALDconsult25-Jul-11 2:44
mvePIEBALDconsult25-Jul-11 2:44 
AnswerRe: data filter options for grid Pin
robertalis26-Jul-11 1:48
robertalis26-Jul-11 1:48 
QuestionHow can I check if my IIS is alive using C#? Pin
goldsoft24-Jul-11 4:17
goldsoft24-Jul-11 4:17 
AnswerRe: How can I check if my IIS is alive using C#? Pin
Mark Salsbery24-Jul-11 8:03
Mark Salsbery24-Jul-11 8:03 
Questionlooking for regex format Pin
Gali197822-Jul-11 21:44
Gali197822-Jul-11 21:44 
AnswerRe: looking for regex format Pin
l a u r e n23-Jul-11 1:46
l a u r e n23-Jul-11 1:46 
AnswerRe: looking for regex format Pin
PIEBALDconsult23-Jul-11 4:07
mvePIEBALDconsult23-Jul-11 4:07 
AnswerRe: looking for regex format Pin
OriginalGriff23-Jul-11 22:05
mveOriginalGriff23-Jul-11 22:05 
QuestionEF 4.1 Pin
mehrdadc4822-Jul-11 21:37
mehrdadc4822-Jul-11 21:37 
AnswerRe: EF 4.1 Pin
Mark Salsbery23-Jul-11 14:37
Mark Salsbery23-Jul-11 14:37 
GeneralRe: EF 4.1 Pin
mehrdadc4823-Jul-11 18:21
mehrdadc4823-Jul-11 18:21 
GeneralRe: EF 4.1 Pin
Mark Salsbery23-Jul-11 21:11
Mark Salsbery23-Jul-11 21:11 

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.