PC Review


Reply
Thread Tools Rate Thread

can someone clarify the foreach for me pls

 
 
Daniel
Guest
Posts: n/a
 
      14th Jun 2006
Hey guys in this code:

public bool DealPlayerOut(int tableId, int playerId)

{

Room theRoom = FindRoom(tableId);

foreach(Seat s in theRoom.RoomTable.Seats)

{

if(!s.Available)

{

if(!(s.Player == null))

{

if(s.player.Id.Equals(playerId)

{

s.Player.PlayerState = PokerPlayer.PokerPlayerStates.DealOut;

return true;

}

}

}

}

return false;

}


Will the playerstate now be set to dealout in the table object originally
referenced? Can you use foreach statements to set variables of the objects
or is it purely for a read only usage?


 
Reply With Quote
 
 
 
 
Barry Kelly
Guest
Posts: n/a
 
      14th Jun 2006
"Daniel" <(E-Mail Removed)> wrote:

> Will the playerstate now be set to dealout in the table object originally
> referenced? Can you use foreach statements to set variables of the objects
> or is it purely for a read only usage?


The "read-only" with foreach applies to the *collection* over which
you're iterating. If modifying the property on the Player causes the
collection to change, then it isn't safe. If modifying the property on
the Player doesn't affect the collection (i.e. the property setter
doesn't try to add or remove from the collection), then it's OK.

-- Barry

--
http://barrkel.blogspot.com/
 
Reply With Quote
 
sternr
Guest
Posts: n/a
 
      14th Jun 2006
You can

Daniel wrote:
> Hey guys in this code:
>
> public bool DealPlayerOut(int tableId, int playerId)
>
> {
>
> Room theRoom = FindRoom(tableId);
>
> foreach(Seat s in theRoom.RoomTable.Seats)
>
> {
>
> if(!s.Available)
>
> {
>
> if(!(s.Player == null))
>
> {
>
> if(s.player.Id.Equals(playerId)
>
> {
>
> s.Player.PlayerState = PokerPlayer.PokerPlayerStates.DealOut;
>
> return true;
>
> }
>
> }
>
> }
>
> }
>
> return false;
>
> }
>
>
> Will the playerstate now be set to dealout in the table object originally
> referenced? Can you use foreach statements to set variables of the objects
> or is it purely for a read only usage?


 
Reply With Quote
 
Michael Nemtsev
Guest
Posts: n/a
 
      14th Jun 2006
Hello Daniel,

Did u read that http://msdn2.microsoft.com/en-us/library/ttw7t8t6.aspx ?


D> Hey guys in this code:
D>
D> public bool DealPlayerOut(int tableId, int playerId)
D>
D> {
D>
D> Room theRoom = FindRoom(tableId);
D>
D> foreach(Seat s in theRoom.RoomTable.Seats)
D>
D> {
D>
D> if(!s.Available)
D>
D> {
D>
D> if(!(s.Player == null))
D>
D> {
D>
D> if(s.player.Id.Equals(playerId)
D>
D> {
D>
D> s.Player.PlayerState = PokerPlayer.PokerPlayerStates.DealOut;
D>
D> return true;
D>
D> }
D>
D> }
D>
D> }
D>
D> }
D>
D> return false;
D>
D> }
D>
D> Will the playerstate now be set to dealout in the table object
D> originally referenced? Can you use foreach statements to set
D> variables of the objects or is it purely for a read only usage?
D>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


 
Reply With Quote
 
Daniel
Guest
Posts: n/a
 
      14th Jun 2006
Yes but it just stalks of reading not modifying. I get it now thanks guys,
just wanted to be sure i had the right understanding.

"Michael Nemtsev" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello Daniel,
>
> Did u read that http://msdn2.microsoft.com/en-us/library/ttw7t8t6.aspx ?
>
>
> D> Hey guys in this code:
> D> D> public bool DealPlayerOut(int tableId, int playerId)
> D> D> {
> D> D> Room theRoom = FindRoom(tableId);
> D> D> foreach(Seat s in theRoom.RoomTable.Seats)
> D> D> {
> D> D> if(!s.Available)
> D> D> {
> D> D> if(!(s.Player == null))
> D> D> {
> D> D> if(s.player.Id.Equals(playerId)
> D> D> {
> D> D> s.Player.PlayerState = PokerPlayer.PokerPlayerStates.DealOut;
> D> D> return true;
> D> D> }
> D> D> }
> D> D> }
> D> D> }
> D> D> return false;
> D> D> }
> D> D> Will the playerstate now be set to dealout in the table object
> D> originally referenced? Can you use foreach statements to set
> D> variables of the objects or is it purely for a read only usage?
> D> ---
> WBR,
> Michael Nemtsev :: blog: http://spaces.msn.com/laflour
>
> "At times one remains faithful to a cause only because its opponents do
> not cease to be insipid." (c) Friedrich Nietzsche
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Just Want To Clarify Before I Try This... =?Utf-8?B?TGl6?= Windows XP Help 6 16th Nov 2007 10:56 PM
DAL or BOL? Can someone clarify? Nemisis Microsoft ASP .NET 2 20th Sep 2006 11:19 AM
foreach or List.ForEach =?Utf-8?B?VHJpcHBlcg==?= Microsoft C# .NET 27 25th Jan 2006 08:35 AM
need to clarify =?Utf-8?B?Sm9obiBTYXd5ZXI=?= Microsoft Excel Charting 0 18th Jul 2005 02:05 PM
Clarify something for me... Cliff Microsoft Windows 2000 Terminal Server Applications 0 27th Apr 2004 05:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:20 PM.