new at c# quikQuestion??? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

new at c# quikQuestion???

programTomprogramTom Posts: 33Member
[code]
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;
}

}

[/code]

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

Comments

  • bmjcpobmjcpo Posts: 18Member
    : [code]
    : 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;
    : }
    :
    : }
    :
    : [/code]
    :
    : 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
  • programTomprogramTom Posts: 33Member
    : : [code]
    : : 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;
    : : }
    : :
    : : }
    : :
    : : [/code]
    : :
    : : 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
  • anchanch Posts: 4Member
    [b][red]This message was edited by anch at 2006-9-28 22:31:54[/red][/b][hr]
    : [code]
    : 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;
    : }
    :
    : }
    :
    : [/code]
    :
    : 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;
    : }



Sign In or Register to comment.