USING SET IN A C# CLASS

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
C# 
C#
 1210  View(s)
Ratings:
Rate this:
Hi Expert!

I have the 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; }
        get { return this.pam1; }
    }
}

Currently, when I want to change the value of Pam1, I do the following:

int n = 500;
Class1 c1 = new Class1();
c1.ChangePam1(n);
How can I change it using Set?
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Using set in a C# class

    Hi Ashish!

    Try as below

    You can do this (It will call the set):

    public class Class1
    {
        private int pam1;

        public Class1(){}

        private void ChancePam1(int newValue)
        {
            UpdatePam1(newValue);
            pam1 = newValue;
        }

        public int Pam1
        {
            set { ChancePam1(value); }
            get { return this.pam1; }
        }
    }
    Then:

    int n = 500;
    Class1 c1 = new Class1();
    c1.Pam1 = n;

    It may be resolve your problem

      Modified On Apr-06-2013 09:27:00 AM
  1. Vijay Shukla

    Post:100

    Points:700
    Re: Using set in a C# class

    Hi!

    Try this way 

    c1.Pam1 = n;
    Or you can use;

    public int Pam1
    {
        set { ChancePam1(value); }
        get { return this.pam1; }
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!