2013年9月12日星期四

Using a collection of custom structures problems

public struct Actions
{
public int [] X;
public int [] Y; / / Position
public int [] FX ;/ / horizontal one vertical direction 0
public int [] Num ;/ / number
public int [] XZH ;/ / square head a pointed shape 0
public int [] CHang ;/ / length , width or height
public int [] JianGe ;/ / If the number is not zero , there is interval.

public ArrayList JuXing ;/ / set of rectangles
public Rectangle JD ;/ / focus rectangle
public Rectangle YYDFW ;/ / moving range
public int YYDFX ;/ / direction of movement
public Rectangle OOldJiaoDian ;/ / the last time the focus
}
ArrayList ActBack = new ArrayList () ;/ / the set of all actions / / Undo collection

recently engaged in a GDI + drawing in the withdrawal , retreat operation , the basic idea is to put every step of the operation , save it as a custom structure ( with an array of collections to distinguish each step ) , and then in each step important things , there is a set inside, so , undo, backward , when each of the structures can be based on , not the same set , to operate !

But the results showed , public ArrayList JuXing this collection is synchronized !

My intention is that this rectangle, each step every step , not the same , for example , tap the first time only two rectangles , and then tap the second had three rectangles , and found , the actual running , the structure of the set , as long as the assignment , all ActBack inside Actions.JuXing, all be the same .
In C #
feeling inside , as if the structure when using the New , New no new things, are the same thing !

this problem, how can I do it ? Did you into a custom class ? ? please give some ideas ! Thank you !
------ Solution --------- -----------------------------------
structure is a value type , consider using classes to implement .
------ Solution ---------------------------------------- ----
public ArrayList JuXing = new ArrayList ();

each structure must maintain a separate list, rather than pointing to the same one .
------ For reference only -------------------------------------- -


I've used New it. every time before adding the collection inside , a bit on the New , and even , it is used a temporary ArrayList to dump into the same results.

The problem I checked the data , C # inside the structure seems to be no redistribution of the heap , only in the stack.

I was really no way to replace all of the array you see in front of me
public int [] X;
public int [] Y; / / Position
public int [] FX ;/ / horizontal one vertical direction 0
public int [] Num ;/ / number
public int [] XZH ;/ / square head a pointed shape 0
public int [] CHang ;/ / length , width or height
public int [] JianGe ;/ / If the number is not zero , there is interval.

Originally these seven things , but also a self-defined structure ! ! also out of this problem, then you can replace the array ......

damn tired to write a lot more code ..
------ For reference only ---------------------- -----------------
more code you posted to .
------ For reference only -------------------------------------- -
code too much , well ... is not posted, asking many annoying ... and I have changed over, into an array of ..

I'm not familiar with C # ... I do not know C # to write a custom class , what format ..

can help you send an example ?
------ For reference only --------------------------- ------------
class MyClass
{
...
}
and you write the same structure .
------ For reference only -------------------------------------- -
is not your point with a lot of structure variables:
Actions a1 = new Actions ();
a2 = a1;
Actions in this type of reference in a1 a2 sharing.
------ For reference only -------------------------------------- -
Actions acts = new Actions ();
acts.JuXing = jxList;

I like this assignment because that jxList ( collection ) is a global variable , supposedly , every step of the collection inside the count is not the same .
It was discovered that as long as an assignment will cause actins collection inside, all JuXing, all unified .

already encountered this problem once , that is, seven in front of me , a start is a structure , I changed over after normal.
Who knew that underneath the collection inside, they met again.

feeling inside the structure variables , it seems like not using a global variable assignment must be if the array ?

You see the following :
        public struct Actions
        {
            //public DarwTing[] Ting;//梃数组
            public int[] X;
            public int[] Y; //位置
            public int[] FX;//方向   0横向1纵向
            public int[] Num;//数量
            public int[] XZH;//形状  0方头1尖头
            public int[] CHang;//长度,宽或者高
            public int[] JianGe;//如果数量不为0,就有间隔.

            public Rectangle[]  JuXing;//矩形数组      **********************
            public Rectangle JD;//焦点矩形
            public Rectangle YYDFW;//移动范围
            public int YYDFX;//移动方向
            public Rectangle OOldJiaoDian;//上一次的焦点
        }


asterisk that line , I changed the array , and then , when the assignment :
            acts.JuXing = new Rectangle[jxList.Count];
            for (int i = 0; i < jxList.Count; i++)
            {
                object obj = new object();
                obj = jxList[i];
                acts.JuXing[i] = (Rectangle)obj;
            }


Thus, normal again . than above that seven things, here is just a small change in the . those seven things, but also to write special conversion function ..

I really think this issue is a bit mean , why they sent to discussing ... such a structure , not as good as it ... NEW not like new things ... after using it , I really have to be careful !!
------ For reference only ------------------------------------ ---
do not use ArrayList, use the List
acts.JuXing = jxList.ToList ();

------ For reference only ---------------------------------- -----
Thank you, first on here. I will continue ! ~

没有评论:

发表评论