Assume this type:
public class Car { }
And I create an instance of that:
Car myCar = new Car();
Target target = new Target();
target.Model = myCar;
And this is another Type:
public class Target {
public object Model { get; set; }
string GetName(){
//Use Model and return myCar in this Example
}
}
As I showed in code the GetName method must use an object type (Model) and returned the name of instance that is myCar in this example? what is your suggestion is there any way to do this?
Update
How about this:
public class Car {
public string Title { get; set; }
}
And I pass to target: target.Model = Car.Title
And GetName() method returned Title ?
No, this is not possible. Why? Because
myCaris only a name for yourCarinstance inside the scope which you set up the variable for. What gets saved totarget.Modelis a reference to theCarinstance. So, after your sample code, bothmyCarandtarget.Modelreference the same instance ofCar, just with different names. The names themselves are rather unimportant to the execution of the program, it’s just a trick we use to make talking about instances easier.