I want to assign an object of one class to another class by constructor, and retrieve the values of the class assigned by constructor from the class which has the constructor. Sounds confusing, it is too :). Can't handle it. Do you have any ideas? Here is an example code.
public class Class1 { public class1(int value1) { Value1 = value1; } public int Value1 { get;} } public class Class2 { public object Object1 {get; set;} } public class main { Class1 TestClass = new Class1(15); Class2 TestClass1 = new Class2(); public void main() { TestClass1.Object1 = TestClass(); //Now I want to this Console.WriteLine(TestClass1.Object1.Value1); TestClass1.Object1.Value1; } }
TestClass1.Object1 = TestClass();What do you expect to happen here?TestClass1.Object1.Value1;would be seen as a code smell by a good part of developers.Value1from Class2 in most cases. This is a pretty abstract example, but for example if you need to compute something from Value1, why not make Class1 do the math?