I have a list, something like this "List< Block >". What I want is to get a block which is same as one in the list, not the object in the list. And do dome modify with the block and get another one.
But the problem is, after get the block three times (which the list's length is 3) the fourth block is already been modified. I tried all the ways I know, even use "new", it just get the object in the list, not a same one.
So how to solve this?
Here is some of my code:
//This is the list which length is 3
private List<BlockType> blocks;
//At the beginning it was like this but not work
//private List<Block> blocks;
//In a function to get a block type randomly
int blockNum = rand.Next(0, 3); //rand is a Random type
this.cBlock = new Block(blocks[blockNum]); //cBlock is object which I use to do something about the block
//The class Block goes to
class Block
{
private List<Rectangle> _block;
public List<Rectangle> block
{
get { return _block; }
}
private int _blockNum;
public int blockNum
{
get { return _blockNum; }
}
public Block()
{
}
public Block(int blockNum, List<Rectangle> block)
{
this._block = block;
this._blockNum = blockNum;
}
public Block(BlockType block)
{
this._block = block.block;
this._blockNum = block.blockNum;
}
}
//And the BlockType is what I tried but does not work
class BlockType
{
private List<Rectangle> _block;
public List<Rectangle> block
{
get { return _block; }
}
private int _blockNum;
public int blockNum
{
get { return _blockNum; }
}
public BlockType()
{
}
public BlockType(int blockNum, List<Rectangle> block)
{
this._block = block;
this._blockNum = blockNum;
}
}