Hello :)
well... i need to do a simple thing (i guess) but it seems that this is not so simple due to all the complicating examples on the web...

ok. i jast wanna to create a copy of an object! but i want the copy to be seperate from the original, so when i change something in the copy it will not affect the original. in this case i need Shallow-Copy or Deep-Copy? i thought its a Deep-Copy until i saw an example that confused me...

now - how i implement it?

lets say i have this Class -

public class Position
    {
        private bool _Turn;
        private AAAA _EN;


        public bool Turn
        {
            get { return _Turn; }
            set { _Turn = value; }
        }
        public AAAA EN
        {
            get { return _EN; }
            set { _EN = value; }
        }

this is when AAAA is a class too

well, i understand that i needed to add IClonable and Clone() Methode like that:

public class Position: IClonable
    {
        private bool _Turn;
        private AAAA _EN;


        public bool Turn
        {
            get { return _Turn; }
            set { _Turn = value; }
        }
        public AAAA EN
        {
            get { return _EN; }
            set { _EN = value; }
        }

        public Position Clone()
       {
            what in here??? i got confuse...
       }

Hope u understand my question...
Thanks in advance

Comments

Thank u Monarch, but i dont understand the code in there... there are a lot of methods i dont know and i still do not use Generics yet so its not clear to me...

could you please give an example of implementing of this code?
the class ObjectCopier is the class i need to copy or its a class that just help me do that on another class?

Thank u

If you put that code into a file by itself, you'll be able to use it with any class that is serializable, doing this:

Position a = new Position();
Position b = a.Clone();

If you put that code into a file by itself, you'll be able to use it with any class that is serializable, doing this:

Position a = new Position();
Position b = a.Clone();

Thank u - one last thing.. i have notice that i need to make the class "static" for that piece of code will work...
why is that? what will happen to my class after that? it can ruin things?

thanks.. :)

It needs to be static because it is a special type of method known as an 'extension method'. It 'extends' other classes rather than being used by the class it's in.

This question has already been answered. Start a new discussion instead.