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

C#

 
QuestionObjects created in a loop - definition name Pin
DSLoginYea6-Aug-13 2:02
DSLoginYea6-Aug-13 2:02 
AnswerRe: Objects created in a loop - definition name Pin
Dave Kreskowiak6-Aug-13 2:47
mveDave Kreskowiak6-Aug-13 2:47 
AnswerRe: Objects created in a loop - definition name Pin
Clifford Nelson6-Aug-13 8:36
Clifford Nelson6-Aug-13 8:36 
GeneralRe: Objects created in a loop - definition name Pin
DSLoginYea6-Aug-13 9:28
DSLoginYea6-Aug-13 9:28 
GeneralRe: Objects created in a loop - definition name Pin
nick.j.s6-Aug-13 10:51
nick.j.s6-Aug-13 10:51 
GeneralRe: Objects created in a loop - definition name Pin
DSLoginYea6-Aug-13 10:55
DSLoginYea6-Aug-13 10:55 
GeneralRe: Objects created in a loop - definition name Pin
Dave Kreskowiak6-Aug-13 10:59
mveDave Kreskowiak6-Aug-13 10:59 
GeneralRe: Objects created in a loop - definition name Pin
Dave Kreskowiak6-Aug-13 10:59
mveDave Kreskowiak6-Aug-13 10:59 
No, there really isn't a name for it because, in your loop, you only ever have one object instance!

You're not creating "multiple objects with the same identifier". Only one instance of that class is ever alive. On the next iteration of the loop, the object created in the last iteration is already gone.


DSLoginYea wrote:
Code:
 
TestA a = new TestA();
TestA a = new TestA();

 
Result: "A local variable named a is already defined in this
scope"
 

However, that is allowed in a loop


No, the loop does not get around that limitation. It's still there. You're not understanding what's going on inside the loop!


DSLoginYea wrote:
I have modified my code below - the 10 objects of type TestA are all named "a".
They will still remain in scope (and not ready garbage collection) after the
loop that created them has finished.
 

ArrayList anArrayList =
new ArrayList();
 

for (int i = 0; i < 10;
i++)
{
TestA a = new TestA();

anArrayList.Add(a);
}

Now you've changed the entire circumstances surrounding the creation of the objects. Now, since you have an array (outside the loop!) holding onto the references of those objects you created inside the loop, the objects are still be references by outside code and do not fall out of scope until the array falls out of scope.

Still, there is no name for this. You're just creating an array, or collection, and filling it with objects created by a loop.

AnswerRe: Objects created in a loop - definition name Pin
Jean A Brandelero8-Aug-13 10:43
Jean A Brandelero8-Aug-13 10:43 
QuestionWah Wah effect for guitar Pin
paulera6-Aug-13 1:52
paulera6-Aug-13 1:52 
AnswerRe: Wah Wah effect for guitar Pin
Ravi Bhavnani6-Aug-13 6:02
professionalRavi Bhavnani6-Aug-13 6:02 
GeneralRe: Wah Wah effect for guitar Pin
paulera6-Aug-13 8:21
paulera6-Aug-13 8:21 
AnswerRe: Wah Wah effect for guitar Pin
MarkRHolbrook11-Aug-13 4:04
MarkRHolbrook11-Aug-13 4:04 
GeneralAdding digital signature in Crystal report pdf Pin
gandhipurvi6-Aug-13 0:25
gandhipurvi6-Aug-13 0:25 
GeneralRe: Adding digital signature in Crystal report pdf Pin
Ennis Ray Lynch, Jr.6-Aug-13 2:55
Ennis Ray Lynch, Jr.6-Aug-13 2:55 
QuestionDatetime parsing Pin
ExcellentOrg5-Aug-13 21:58
ExcellentOrg5-Aug-13 21:58 
AnswerRe: Datetime parsing Pin
Richard MacCutchan5-Aug-13 22:58
mveRichard MacCutchan5-Aug-13 22:58 
GeneralRe: Datetime parsing Pin
ExcellentOrg5-Aug-13 23:30
ExcellentOrg5-Aug-13 23:30 
AnswerRe: Datetime parsing Pin
Richard MacCutchan6-Aug-13 0:04
mveRichard MacCutchan6-Aug-13 0:04 
GeneralRe: Datetime parsing Pin
ExcellentOrg6-Aug-13 9:19
ExcellentOrg6-Aug-13 9:19 
AnswerRe: Datetime parsing Pin
Richard MacCutchan6-Aug-13 0:09
mveRichard MacCutchan6-Aug-13 0:09 
GeneralRe: Datetime parsing Pin
ExcellentOrg6-Aug-13 9:10
ExcellentOrg6-Aug-13 9:10 
AnswerRe: Datetime parsing Pin
Mycroft Holmes6-Aug-13 12:56
professionalMycroft Holmes6-Aug-13 12:56 
GeneralRe: Datetime parsing Pin
ExcellentOrg6-Aug-13 18:52
ExcellentOrg6-Aug-13 18:52 
AnswerRe: Datetime parsing Pin
ExcellentOrg7-Aug-13 7:57
ExcellentOrg7-Aug-13 7:57 

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.