Click here to Skip to main content
15,886,199 members
Home / Discussions / C#
   

C#

 
GeneralSomething basic Pin
Spykraft29-Apr-08 7:13
Spykraft29-Apr-08 7:13 
GeneralRe: Something basic Pin
PIEBALDconsult29-Apr-08 7:24
mvePIEBALDconsult29-Apr-08 7:24 
GeneralRe: Something basic Pin
carbon_golem29-Apr-08 7:28
carbon_golem29-Apr-08 7:28 
GeneralRe: Something basic Pin
PIEBALDconsult29-Apr-08 12:11
mvePIEBALDconsult29-Apr-08 12:11 
GeneralRe: Something basic Pin
Spykraft29-Apr-08 7:38
Spykraft29-Apr-08 7:38 
GeneralRe: Something basic Pin
carbon_golem29-Apr-08 8:06
carbon_golem29-Apr-08 8:06 
GeneralRe: Something basic Pin
Spykraft29-Apr-08 12:11
Spykraft29-Apr-08 12:11 
GeneralRe: Something basic Pin
carbon_golem29-Apr-08 16:59
carbon_golem29-Apr-08 16:59 
Spykraft wrote:
carbon_golem wrote:
Have you timed it yourself?



Nope I havent timed it yet, how do i do that?


Look at the Stopwatch class, create a bunch of instances in a tight loop and time it. divide by your for loop parameter.


Spykraft wrote:
However compare it to the scenario where the class A and class B objects are being created more than once in Class C, would it be more economical to invoke the constructors everytime and initialize the members, even if we dont need them to be initialized; or just call a method once and pass the object references to initialize them once?


That depends... if you're using the class as purely an initializer and not a member, then yes it is more economical. Say you're using class A to initialize class B then throwing A aside, then that's better to use it that way. And that's leaning more toward the Factory Pattern.[^].
If you're keeping A as a member in C then in that situation, then you'll probably want to give C it's own copy. If you make A temp = new A(); and pass temp to every instance of C that is being created, then all C's copies of A point to the same object. Thus any changes to A have a profound effect on your program. If that's the situation, then consider a redesign. But for the sake of argument, that's the fastest solution because there's one initialization and method calls proportional to the number of C's you have.

Hope this helps...

Scott P

"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand

GeneralRe: Something basic Pin
PIEBALDconsult29-Apr-08 9:31
mvePIEBALDconsult29-Apr-08 9:31 
GeneralDatagridview and keyenter Pin
Canann29-Apr-08 4:43
Canann29-Apr-08 4:43 
QuestionRe: Datagridview and keyenter Pin
Canann30-Apr-08 2:51
Canann30-Apr-08 2:51 
QuestionHow to generate Typed DataSet with CodeDom ? Pin
hdv21229-Apr-08 3:03
hdv21229-Apr-08 3:03 
Generalanti-pattern in GC Pin
George_George29-Apr-08 2:59
George_George29-Apr-08 2:59 
GeneralRe: anti-pattern in GC Pin
Colin Angus Mackay29-Apr-08 4:03
Colin Angus Mackay29-Apr-08 4:03 
GeneralRe: anti-pattern in GC Pin
George_George29-Apr-08 4:26
George_George29-Apr-08 4:26 
GeneralRe: anti-pattern in GC Pin
led mike29-Apr-08 4:53
led mike29-Apr-08 4:53 
GeneralRe: anti-pattern in GC Pin
George_George29-Apr-08 4:59
George_George29-Apr-08 4:59 
GeneralRe: anti-pattern in GC Pin
led mike29-Apr-08 5:40
led mike29-Apr-08 5:40 
GeneralRe: anti-pattern in GC Pin
George_George29-Apr-08 20:41
George_George29-Apr-08 20:41 
GeneralRe: anti-pattern in GC Pin
led mike30-Apr-08 4:50
led mike30-Apr-08 4:50 
GeneralRe: anti-pattern in GC Pin
George_George30-Apr-08 22:06
George_George30-Apr-08 22:06 
GeneralRe: anti-pattern in GC Pin
led mike1-May-08 6:18
led mike1-May-08 6:18 
GeneralRe: anti-pattern in GC Pin
George_George1-May-08 21:47
George_George1-May-08 21:47 
Generalinserting string into string Pin
stephan_00729-Apr-08 2:59
stephan_00729-Apr-08 2:59 
GeneralRe: inserting string into string Pin
carbon_golem29-Apr-08 3:58
carbon_golem29-Apr-08 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.