Home > other >  Ask a grammar question...
Ask a grammar question...

Time:09-21

Public Vector3 v1.
Public Vector3 v2 {set; The get; }

V1 Set (1, 2, 3)
V2. The Set (1, 2, 3)

Print (v1); Print 1, 2, 3
Print (v2); Print 0 0,


Why is v2 print 000, strives for the detailed explanation!

CodePudding user response:

This involves the c # syntax - attributes:
V2 {set; The get; }
Set is to set a value, the get is to get the value, so the v2 should return the value of the set set up inside,
For example:
Public int the name;
Public int the Name {
The set {
Name=value;
}
The get {
return name;
}
}
Name="Hello";
The Console. Write (" the Name is: {0} ", Name);

CodePudding user response:

reference 1st floor xujin12368 response:
this involves c # syntax - attributes:
V2 {set; The get; }
Set is to set a value, the get is to get the value, so the v2 should return the value of the set set up inside,
For example:
Public int the name;
Public int the Name {
The set {
Name=value;
}
The get {
return name;
}
}
Name="Hello";
The Console. Write (" the Name is: {0} ", Name);

I write the wrong type, change that int to a string...

CodePudding user response:

refer to the second floor xujin12368 response:
Quote: refer to 1st floor xujin12368 response:

This involves the c # syntax - attributes:
V2 {set; The get; }
Set is to set a value, the get is to get the value, so the v2 should return the value of the set set up inside,
For example:
Public int the name;
Public int the Name {
The set {
Name=value;
}
The get {
return name;
}
}
Name="Hello";
The Console. Write (" the Name is: {0} ", Name);

I write the wrong type, change that int to a string...


I am to ask why the v2 is 0 0 0...... can answer detailed point

CodePudding user response:

V2 is properties, only through=assignment, so the print of the default value of v2 Vector3 (0, 0), should be this: v2=new Vector3 (1, 2, 3); Print (v2);

CodePudding user response:

Upstairs, with the reference
http://www.runoob.com/csharp/csharp-property.html
  • Related