vb.net - Passing structure to a procedure as ByValue, however the procedure changes original structure values -
i want ask vb.net code. i'm suffering problem lot. please answer me if know solution of question or give me comments.
'declare structure "gene" public structure gene dim seq() integer end structure 'here procedure, changes original value. public sub mutation(byval originalgene gene, byref targetgene gene) dim p1 integer dim p2 integer dim temp integer p1 = int((n_jobs - 1 + 1) * rnd(rndnum) + 0) p2 = int((n_jobs - 1 + 1) * rnd(rndnum + 1) + 0) targetgene.seq = originalgene.seq temp = targetgene.seq(p1) targetgene.seq(p1) = targetgene.seq(p2) targetgene.seq(p2) = temp end sub
it's not changing structure. structure contains pointer array. reference array same though can have unlimited number of copies of structure.
example of immutable gene class:
public class gene private _sequence() integer public sub new(sequence() integer) _sequence = sequence end sub public function getsequence() integer() return _sequence.select(function (x) x).toarray() end function public function mutate() gene dim sequence() integer = me.getsequence() dim p1 integer dim p2 integer dim temp integer p1 = int((n_jobs - 1 + 1) * rnd(rndnum) + 0) p2 = int((n_jobs - 1 + 1) * rnd(rndnum + 1) + 0) targetgene.seq = originalgene.seq temp = sequence(p1) sequence(p1) = sequence(p2) sequence(p2) = temp return new gene(sequence) end function end class
Comments
Post a Comment