Using {set; get;} instead of {get; set;}

In C # languages ​​and its cousins ​​we always use

public string SomeString { get; set;}

But you can also use (I found this only recently and while cheating with the compiler)

public string SomeString { set; get; }

I have no formal training in programming, and all are conceivable. I used { get; set; }without any thoughts like us. 1 + 1 = 2Is order { get; set; }just a convention, or is it necessary to maintain that order, or is it some kind of remnant of a past era of history C, similar to how we define an ordinary electric current flowing from a positive to a negative terminal when it is actually the other way around?

+4
source share
6 answers

No difference.

, getter , setter . :

public String getSomeString() { return someString; }
public void setSomeString(String value) { someString=value; }

public void setSomeString(String value) { someString=value; }
public String getSomeString() { return someString; }

. ?

. :)

+4

. , .

+8

.

# http://msdn.microsoft.com/en-us/library/ms228593.aspx, 10.7.2 (. 324)

- , .

-:

get-accessor-declaration   set-accessor-declaration
set-accessor-declaration   get-accessor-declaration

, ,

+2

Get Set - ,

private PropertyType Get() {}
private Set(value as PropertyType) {} 

, .

MSDN:

. .


, void. , , .

+2

{ get; set; } - , , . ,

public string GetSomeString() { }
public void SetSomeString(string value) { } 

, ? , .

+1

:

        public string SomeString { get; set; }
    public string SomeString2 { set; get; }

    public string someString2;

    public string SomeString21
    {
        get { return someString2; }
        set { someString2 = value; }
    }

    public string SomeString22
    {
        set { someString2 = value; }
        get { return someString2; }
    }

    public string SomeString23
    {
        set { someString2 = value; }
    }

    public string SomeString24
    {
        get { return someString2; }
    }
+1

All Articles