搞编程的,在工作中学习中,除了培养好的代码习惯、养成自己的一套代码风格,还需要多思考如何把代码写的更健壮,碰到bug如何去调试呢,与诸君共勉。
...
return this.RedProperty.CopyTo(temp.RedProperty) &&
this.GreenProperty.CopyTo(temp.GreenProperty) &&
this.BlueProperty.CopyTo(temp.BlueProperty) &&
this.VRedProperty.CopyTo(temp.VRedProperty);
...
ToArray 方法中的条件判断可以简化为 return data != null && data.Length > 0x82;,
//因为它们的结果已经是布尔值。
FromArray 方法中的条件判断可以简化为 return data.Length == MaxValueInfo.MAX_PARAMETER_TABLE_LEN;//因为它们的结果已经是布尔值。
public IEnumerator GetEnumerator()
{
return this.carArray.GetEnumerator();
}
//如下:
namespace ForeachTestCase
{
// 继承 IEnumerable 接口,其实也可以不继承这个接口,只要类里面含有返回 IEnumberator 引用的 GetEnumerator () 方法即可
class ForeachTest:IEnumerable
{
...
//实现接口中得方法
public IEnumerator GetEnumerator()
{
return new ForeachTestEnumerator(this);
}
private class ForeachTestEnumerator : IEnumerator
{
private int position = -1;
private ForeachTest t;
public ForeachTestEnumerator(ForeachTest t)
{
this.t = t;
}
#region 实现接口
public object Current
{
get
{
return t.elements[position];
}
}
public bool MoveNext()
{
if (position < t.elements.Length - 1)
{
position++;
return true;
}
else
{
return false;
}
}
......
}