Best Method to Instantiate a Class
-
I have three different ways to Instatiate a class and fill the properties. Even though all three ways work I'm not sure which would be the best to use in the form "Best Practices" Method 1 Simple instantiate class, set property and call select to fill object
Foo NewFoo = new Foo();
NewFoo.ID = 10;
NewFoo.Select();Method 2 In constructor Set Id and then call Select to Fill Object
Foo NewFoo = new Foo(10).Select();
Method 3 In the construtor I use the ID and automatically call the Select to fill the Object
Foo NewFoo = new Foo(10);
All three are basically the same. If anyone does it differently or better. Please let me know what your thoughts are. Thanks.
-
I have three different ways to Instatiate a class and fill the properties. Even though all three ways work I'm not sure which would be the best to use in the form "Best Practices" Method 1 Simple instantiate class, set property and call select to fill object
Foo NewFoo = new Foo();
NewFoo.ID = 10;
NewFoo.Select();Method 2 In constructor Set Id and then call Select to Fill Object
Foo NewFoo = new Foo(10).Select();
Method 3 In the construtor I use the ID and automatically call the Select to fill the Object
Foo NewFoo = new Foo(10);
All three are basically the same. If anyone does it differently or better. Please let me know what your thoughts are. Thanks.
I would use Method 4:) Foo NewFoo = new Foo(10); NewFoo.Select();
-
I would use Method 4:) Foo NewFoo = new Foo(10); NewFoo.Select();