---
title: "Using set in a C# class"  
description: "Using set in a C# class"  
author: "Anonymous User"  
published: 2013-04-06  
updated: 2013-04-06  
canonical: https://www.mindstick.com/forum/727/using-set-in-a-c-sharp-class  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Using set in a C# class

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
\
I have the following [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp):\
\
public class Class1\
{\
[private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) [int](https://www.mindstick.com/forum/159137/how-to-convert-date-int-to-date-in-sql) pam1;\
\
public Class1()\
{\
\
}\
\
[public void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) ChangePam1(int _NewValue)\
{\
UpdatePam1(_NewValue);\
pam1 = _NewValue;\
}\
\
public int Pam1\
{\
set { this.pam1 = [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages); }\
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?\

## Replies

### Reply by Vijay Shukla

Hi!\
Try this way \
c1.Pam1 = n;Or you can use;\
public int Pam1{ set { ChancePam1(value); } get { return this.pam1; }}

### Reply by AVADHESH PATEL

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\


---

Original Source: https://www.mindstick.com/forum/727/using-set-in-a-c-sharp-class

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
