I’m trying to call the constructor of class B from class A by passing some arguments (args1,args2). I am using something like this:
public class A
{
private readonly B _b;
public A()
{
_b=new B(TypeA args1,TypeB args2);
}
...
}
public class B
{
public B(TypeA new_args1,TypeB new_args2)
{
...
}
...
}
But from what I see in debug althougth args1 and args2 have the correct values that I want to send, new_args1 and new_args2 do not change. Is there a specific syntax I have to use to do that?
I’m not sure why you call the args to the constructor of B “new”. They are the arguments for instantiating that particular object instance.
Except for the fact that you’re missing a type in the argument declaration, your code looks correct. What exactly is wrong.
is missing the types, e.g.
Given the type assumption above
would cause B to be initialized as
Assuming you assign those values somewhere in B, e.g.
then
would have the value 42, and
would have the value 24
after you initialize _b.