Structures methods in C#
Forums:
struct Point {
public int x, y;
public string ToString() {
return string.Format("x = {0}; y = {1}", x, y);
}
public void Move(int right, int down) {
x += right;
y += down;
}
}
var p1 = new Point {x = 1, y = 2};
var str1 = p1.ToString();
//str1 is "x = 1; y = 2"
p1.Move(5, -1);
var str2 = p1.ToString();
//str2 is "x = 6; y = 1"
- Log in to post comments