IEnumerator ERROR.............

Posted by Anand under C# on 2/14/2012 | Points: 10 | Views : 877 | Status : [Member] | Replies : 3
using System;
using System.Collections;
class player
{
string name;
int runs;
public player (string name ,int runs)
{
this.name = name;
this.runs = runs;
}
public void print()
{
Console.WriteLine(" name" + name + "runs " + runs);
}

}
class team :IEnumerable
{
public team()
{
player[] p = null;
{
p = new player[3];
p[0] = new player("a", 1);
p[1] = new player("b", 2);
p[2] = new player("c", 3);
p[3] = new player("d", 4);
}

}

public IEnumerator GetEnumerator()
{
return p.GetEnumerator(); I am getting an ERRor on this statement can somebody please tell me what is the probelm
errro is P DOES NOT EXIST IN THE CURRENT CONTEXT

}
}

class program
{
public static void Main()
{
team t = new team();
foreach(player pa in t)
{
pa.print();
}
}
}

-


Responses

Posted by: Naraayanan on: 2/16/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

i changed your code.Please read and use them
 class Player

{
string name;
int runs;
public Player (string name ,int runs)
{
this.name = name;
this.runs = runs;
}
public void print()
{
MessageBox.Show (" name" + name + "runs " + runs);
}


class team : IEnumerable
{
Player[] Ply;
public team()
{

Ply = null;
{
Ply = new Player[4];
Ply[0] = new Player("a", 1);
Ply[1] = new Player("b", 2);
Ply[2] = new Player("c", 3);
Ply[3] = new Player("d", 4);
}
}
public IEnumerator GetEnumerator()
{
return Ply.GetEnumerator();
}

}


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Anand, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anand on: 2/17/2012 [Member] Starter | Points: 25

Up
0
Down
thank u sir

-

Anand, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 2/18/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
No Problem

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Anand, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response