Skip to main content
Milan Dutta (Bankers Life and Casuality) 님이 #Apex에 질문했습니다
Hi experts,

Very basic question and find difficult to understand. And please let me know, when to use what?

What is the difference between these 2 coding structures:

1.  public String name {

         get { return name;}

        set { name = value;}

2. public String name{get;set;}
답변 5개
  1. 2016년 5월 10일 오전 8:40

    Hi,

    Get (getter) method is used to pass value from controller to VF page while set (setter) is used to set the value back to controller variable. 

    Above two methods are same and will return same results. Only their style of coding is different.

    But if you modify getter setter method with below code then it will change the result.

    For example name is 'John'

     public String name {

             get { return name + 'Get Value';}

            set { name = value +' Set Value';}

    In above code getter result will be "John Get Value' and Setter result will be "John Set Value" 

    Please mark it Solved if it has resolved your query.

    Thanks,

    Mayank