我有一个我感兴趣的问题,在编程方面什么会更好:使用Class members
还是Getter
从 My Class 内部?例如这是我的课:
public class myClass
{
private string _name;
private int _length;
private int _weight;
public void doSomething(myClass obj)
{
}
public void doSomething2(myClass obj)
{
}
public string name
{
get { return _name; }
}
public int length
{
get { return _length; }
}
public int weight
{
get { return _weight; }
}
}
以这种方式使用 doSomething:
public void doSomething(string str, myClass obj)
{
string[] arr = str.Split(' ');
arr[1] = obj._name;
arr[2] = obj._length;
arr[3] = obj._weight;
}
或者这样:
public void doSomething2(string str, myClass obj)
{
string[] arr = str.Split(' ');
arr[1] = obj.name;
arr[2] = obj.length;
arr[3] = obj.weight;
}