-1

For example: List = {a,b}

private List<GameObject> FunctionName(List<GameObject> List)
{
    List<GameObject> ListClone = List;
    ListClone.RemoveAt(1);
    
    return List;
}

output: a

Another example:

GameObject a = GameObject b;
Destroy(b);
return a;

output: null

How can i copy the Value not the Address, so that the old Objects doesn't get changed with it?

This is the reason while nothing works like it should and i need a work-around for everything and it takes 10x the amount of time to do anything, so please enlighten me.

Hana
  • 1
  • 3
  • 1
    You should research the difference between reference types and value types. Here's a start: [What is the difference between a reference type and value type in c#?](https://stackoverflow.com/questions/5057267/what-is-the-difference-between-a-reference-type-and-value-type-in-c) – Retired Ninja Dec 22 '21 at 20:36
  • it's not linking anything ... you assign the reference of `b` and store it in a variable called `a` ... => They both now point to the same object ... Se for your list example ... Sounds like you should go through some very basic c# and in general Object Oriented Programming tutorials ;) – derHugo Dec 22 '21 at 20:37
  • @RetiredNinja i did, but how can i only assign the values instead of it direction to the same point now? – Hana Dec 22 '21 at 20:43
  • You want to clone the object: https://dotnetcoretutorials.com/2020/09/09/cloning-objects-in-c-and-net-core/ – Major Productions Dec 29 '21 at 18:14

1 Answers1

-2

If you want to copy the memory-address:

List<GameObject> A = B;

If you want to copy the value of the memory-address:

List<GameObject> A = new List<GameObject>(B);
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Hana
  • 1
  • 3