0

I am having this class:

public class A
{
    public int Var1 { get; set; }
    public int Var2 { get; set; }
    public int Var3 { get; set; }


    public A()
    {

    }

    public void Load(A sender)
    {
        this.Var1 = sender.Var1;
        this.Var2 = sender.Var2;
        this.Var3 = sender.Var3;
    }
}

Since i have a lot of variables in my class, i do not want to assign each value every time inside my Load function, is there a way i say like this = sender since both are same type?

Aleksa Ristic
  • 2,394
  • 3
  • 23
  • 54
  • https://learn.microsoft.com/en-us/dotnet/api/system.object.memberwiseclone?view=netframework-4.8 – Steve Jan 20 '20 at 09:20
  • There is not, and also you are likely writing a copy-constructor so you should declare it as such: `public A(A other)`. – Matthew Watson Jan 20 '20 at 09:20
  • Search for "clone object in c#". – MakePeaceGreatAgain Jan 20 '20 at 09:20
  • I think that this is more of a [`copy constructor`](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-write-a-copy-constructor) problem rather than simple cloning. – Matthew Watson Jan 20 '20 at 09:23
  • I already closed too many posts as duplicates today... When answering "how to clone object" please make sure to meet, or preferably exceed quality of answers to roughly the same question here - https://stackoverflow.com/questions/78536/deep-cloning-objects – Alexei Levenkov Jan 20 '20 at 09:23
  • None of referring comments didn't work and are not same as this case, but answer from HimBromBeere markd question did work. – Aleksa Ristic Jan 20 '20 at 09:50

0 Answers0