Set是包含不重复对象的集合,可以用来对两个集合求交集、并集、差集等运算。SortedSet中的元素可以按照一定规则进行排序,这样可以按照某种顺序遍历元素。这需要创建针对某种类型排序的类,这个类需要实现IComparer接口。比如,我们需要构造类型StateConfigure的SortedSet,就需要有针对StateConfigure的IComparer类,如下:
namespace ZL.FSM.Core.STD
{
class StateConfigureCompare : IComparer<StateConfigure>
{
public int Compare(StateConfigure x, StateConfigure y)
{
return x.DocumentOrder-y.DocumentOrder;
}
}
}
初始化SortedSet<StateConfigure>的代码如下:
var statesToEnter = new SortedSet<StateConfigure>(new StateConfigureCompare());
网友评论