Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 4 characters in body
Source Link
Myles McDonnell
  • 13.4k
  • 20
  • 70
  • 123

You have two instances of MyClass, one you instantiate in the test, the other in MyAnotherClass. If you want to have only one instance you should pass it to the constructor of MyAnotherClass or make an argument of CallingMethod

public class MyAnotherClass { private readonly MyClass _myClass; public MyAnotherClass(MyClass myClass) { _myClass = myClass; } public void CallingMethod(int c, int d) { _myClass.Add( c, d); } } 

You have two instances of MyClass, one you instantiate in the test, the other in MyAnotherClass. If you want to have only instance you should pass it to the constructor of MyAnotherClass or make an argument of CallingMethod

You have two instances of MyClass, one you instantiate in the test, the other in MyAnotherClass. If you want to have only one instance you should pass it to the constructor of MyAnotherClass or make an argument of CallingMethod

public class MyAnotherClass { private readonly MyClass _myClass; public MyAnotherClass(MyClass myClass) { _myClass = myClass; } public void CallingMethod(int c, int d) { _myClass.Add( c, d); } } 
Source Link
Myles McDonnell
  • 13.4k
  • 20
  • 70
  • 123

You have two instances of MyClass, one you instantiate in the test, the other in MyAnotherClass. If you want to have only instance you should pass it to the constructor of MyAnotherClass or make an argument of CallingMethod