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

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.