.net - Using set in a C# class -


i have following class:

public class class1 {     private int pam1;      public class1()     {      }      public void changepam1(int _newvalue)     {         updatepam1(_newvalue);         pam1 = _newvalue;     }      public int pam1     {         set { this.pam1 = value; }         { return this.pam1; }     } } 

currently, when want change value of pam1, following:

int n = 500; class1 c1 = new class1(); c1.changepam1(n); 

how can change using set?

you can (it call set):

public class class1 {     private int pam1;      public class1(){}      private void chancepam1(int newvalue)     {         updatepam1(newvalue);         pam1 = newvalue;     }      public int pam1     {         set { chancepam1(value); }         { return this.pam1; }     } } 

then:

int n = 500; class1 c1 = new class1(); c1.pam1 = n; 

also have @ this.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -