C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
new at c# quikQuestion??? Posted by programTom on 18 Sept 2006 at 6:19 AM
        public string ItemList
        {
            get
            { 
                    foreach (Thing thing in _Things)
                    {
                        
                        _itemList = thing.Name;
                        //so far this is the only way i can 
                        //show multiple thing.Names in _Things
                        // but i want to return this, not write it to
                        //the console.
                        Console.WriteLine("{0}",_itemList);
                        
                    }
                    
                    return _itemList;
            }
                
        }



i want to return all of the thing.Names in _Things (_Things is a list of thing)...i that makes sense......

I added more than one thing into the _Things list,, but it is only returning the last thing.Name in the _Things list..........

this may not make much sense but if any1 can help..that would b great
Report
Re: new at c# quikQuestion??? Posted by bmjcpo on 20 Sept 2006 at 1:02 AM
:
:         public string ItemList
:         {
:             get
:             { 
:                     foreach (Thing thing in _Things)
:                     {
:                         
:                         _itemList = thing.Name;
:                         //so far this is the only way i can 
:                         //show multiple thing.Names in _Things
:                         // but i want to return this, not write it to
:                         //the console.
:                         Console.WriteLine("{0}",_itemList);
:                         
:                     }
:                     
:                     return _itemList;
:             }
:                 
:         }
: 
: 

:
: i want to return all of the thing.Names in _Things (_Things is a list of thing)...i that makes sense......
:
: I added more than one thing into the _Things list,, but it is only returning the last thing.Name in the _Things list..........
:
: this may not make much sense but if any1 can help..that would b great
:

hi,
Sure, just use an array in your 'foreach'-loop. Fill that array with your list items, and return your array on the place where in your code 'return _itemList;' stands.
good luck
Report
Re: new at c# quikQuestion??? Posted by programTom on 20 Sept 2006 at 4:24 AM
: :
: :         public string ItemList
: :         {
: :             get
: :             { 
: :                     foreach (Thing thing in _Things)
: :                     {
: :                         
: :                         _itemList = thing.Name;
: :                         //so far this is the only way i can 
: :                         //show multiple thing.Names in _Things
: :                         // but i want to return this, not write it to
: :                         //the console.
: :                         Console.WriteLine("{0}",_itemList);
: :                         
: :                     }
: :                     
: :                     return _itemList;
: :             }
: :                 
: :         }
: : 
: : 

: :
: : i want to return all of the thing.Names in _Things (_Things is a list of thing)...i that makes sense......
: :
: : I added more than one thing into the _Things list,, but it is only returning the last thing.Name in the _Things list..........
: :
: : this may not make much sense but if any1 can help..that would b great
: :
:
: hi,
: Sure, just use an array in your 'foreach'-loop. Fill that array with your list items, and return your array on the place where in your code 'return _itemList;' stands.
: good luck
:
Thanks heaps...worknin nice now
Report
Re: new at c# quikQuestion??? Posted by anch on 28 Sept 2006 at 10:28 PM
This message was edited by anch at 2006-9-28 22:31:54

:
:         public string ItemList
:         {
:             get
:             { 
:                     foreach (Thing thing in _Things)
:                     {
:                         
:                         _itemList = thing.Name;
:                         //so far this is the only way i can 
:                         //show multiple thing.Names in _Things
:                         // but i want to return this, not write it to
:                         //the console.
:                         Console.WriteLine("{0}",_itemList);
:                         
:                     }
:                     
:                     return _itemList;
:             }
:                 
:         }
: 
: 

:
: i want to return all of the thing.Names in _Things (_Things is a list of thing)...i that makes sense......
:
: I added more than one thing into the _Things list,, but it is only returning the last thing.Name in the _Things list..........
:
: this may not make much sense but if any1 can help..that would b great
:


try the following code



get
: {
: _itemList = "";
foreach (Thing thing in _Things)
: {
:
: _itemList += thing.Name;
:
: }
:
: return _itemList;
: }






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.