Thanks for help with the question I just submitted about anonymous classes. Now I understand more. Here’s a bit more of an example:
public class abc {
public xx doAction() {
return ( new { ID = 5, Name= "Dave" } );
}
public void doStart() {
var a = doAction();
var b = a.ID;
var c = a.Name;
}
}
So am I correct in saying that the most ideal way to do this would be to declare a class XYX and use it like this:
public class abc {
public XYZ doAction() {
return ( new XYZ { ID = 5, Name= "Dave" } );
}
public void doStart() {
var a = doAction();
var b = a.ID;
var c = a.Name;
}
}
The class would be only used for this one data transfer between the two methods.
I think you meant: return new XYZ(5, “Dave”)
Anyways, your solution is okay but there is no reason to create a new class simply to share data. You can use a hashtable/array/dictionary or whatever class suits you best to share data. If you want to do something special with the XYZ class, or it has methods you wish to call from it, then you would have to create a new class XYZ and return it. Though, if you just want to share data, use a data structure that’s already available to your use.