請幫我在這個問題上參數對象也發生了變化時,該方法返回相同類型的對象
我創建了一個對象節點
public Node(HashSet<string> _id, double _weight, List<string> _diff, int _depth, HashSet<string> _prefix, int _support)
{
Id = _id;
Weight = _weight;
Diffset = _diff;
Depth = _depth;
Prefix = _prefix;
Support = _support;
Isleaf = false;
Weightsup = _support*_weight;
}
我創建了一個方法,像這樣和傳遞三個參數
public Node CreateTailNode(Node _a, Node _b, Double _minsup)
{
Node _child = new Node();
_child.Prefix = _a.Id;
_child.Id = _a.Id.AddRange(_b.Id);
_child.Depth = _a.Depth + 1;
_child.Diffset = _a.Diffset.Except(_b.Diffset).ToList();
_child.Weight = (_a.Weight + _b.Weight)/2;
_child.Support = _a.Support - _child.Diffset.Count;
_child.Weightsup = _child.Support*_child.Weight;
if (_child.Weightsup < _minsup)
{
_child.Isleaf = true;
}
else
{
_child.Isleaf = false;
}
return _child;
}
回報_child後,我意識到,節點_a.Prefix也發生變化,得出了同樣的_child.Prefix
如何創建_child而無需更改節點的前綴_a
_a和_b是引用類型。調用此方法後,這些對象中的任何更改都會出現。查看「_a.Id.AddRange(_b.Id)」語句。 –