My question is realy simple. I need to create 20.000 istances of a class, and I want to understand if it's best in terms of memory to put a method inside the instanciated class or if it's better to have only one method in the calling class, and then pass to it the single class properties I need to compute.
I mean, in terms of memory, it's best:
Scenario a)
public class b
{
public string name;
public string result;
}
public class a
{
public string myMethod(string name)
{
//do complex things... long method...
}
//create 20.000 istances of class b
//and when I need it... I take one of them and do something like...
myclassB.result=myMethod(myclassB.name)
}
OR Scenario b)
public class b
{
private string name;
private string result;
private string myMethod()
{
//do complex things... long method...
result="something";
}
}
public class a
{
//create 20.000 istances of class b
//and when I need it... I take one of them and do something like...
myclassB.myMethod();
}
I mean, when I create 20.000 istances of the class with a method inside of it, will .net "duplicate" the method 20.000 times in memory ? Or it will only create one and then handle it by his own ?