본문 바로가기
Unity3D/Unity & C#

Unity & C# ~ Property 프로퍼티

by 캬캬백곰 2022. 4. 27.
728x90

최종 수정 : 22.09.23

 

참조 : https://stackoverflow.com/questions/3847832/understanding-private-setters

 

understanding private setters

I don't understand the need of having private setters which started with C# 2. Having a setter method for me is letting the user to set some variables in that class. In doing so, we will not expo...

stackoverflow.com

 

//int 자리에 자료형 대입
public int parameters { get; set; }

public string parameters { get; private set; }

public string parameters { get; private set; } = "abc";


privaet float parameters = 0.0f;
public float Parameters { get { return parameters; } set { parameters = value; } }

privaet float parameters = 0.0f;
public float Parameters { get { return parameters; } private set { parameters = value; } }

privaet float parameters = 0.0f;
public float Parameters { get => parameters;
						  set => parameters = value; }
                          
privaet float parameters = 0.0f;
public float Parameters { get { return parameters; } 
						  set 
                          {
                            if(value == 1)
                            	parameters = value + 1;
                            else
                            	parameters = value;
                          } 
                        }
728x90
반응형