Click here to Skip to main content
15,890,438 members
Home / Discussions / C#
   

C#

 
AnswerRe: Serialize System.Web.UI.WebControls.Unit Pin
Steve Hansen13-Mar-06 23:06
Steve Hansen13-Mar-06 23:06 
GeneralRe: Serialize System.Web.UI.WebControls.Unit Pin
Foxcoming14-Mar-06 14:01
Foxcoming14-Mar-06 14:01 
GeneralRe: Serialize System.Web.UI.WebControls.Unit Pin
Steve Hansen14-Mar-06 19:58
Steve Hansen14-Mar-06 19:58 
Questionproject Pin
ali kanju13-Mar-06 21:51
ali kanju13-Mar-06 21:51 
AnswerRe: project Pin
J4amieC13-Mar-06 22:06
J4amieC13-Mar-06 22:06 
AnswerRe: project Pin
Steve Pullan14-Mar-06 12:09
Steve Pullan14-Mar-06 12:09 
QuestionClass Inheritance and Propertys Pin
Steini kallinn13-Mar-06 21:06
Steini kallinn13-Mar-06 21:06 
AnswerRe: Class Inheritance and Propertys Pin
J4amieC13-Mar-06 22:03
J4amieC13-Mar-06 22:03 
Starting at your top level

static public Player[] player = new Player[2];

This line is fine, it declares an array of Player objects, but importantly does NOT instantiate any Player instances.

player[0].Cards[0].GetSuit();

This line is fine, in principle, however note the above comment about no Players having been instantiated. This line would cause a null reference exception even if Player had been defined correctly.

so lets add this instead (purposly missing out unimportant stuff):

static public Player[] players = new Player[2];	
static void Main(string[] args)
{
    players[0] = new PLayer("Jim");
    players[1] = new Player("Bob");
    int suit = players[0].Cards[0].GetSuit();
}


This now looks better as players[0] & players[1] are instantiated with new Player instances. Breaking the final line down:

int suit = - your GetSuit() method returned an integer, so I am capturing that return. You may wish to consider using an Enum for Suit, but this is a personal preference

players[0] - this will work as-is because players is an array which already has a numeric indexer

Cards[0] - your Player object will need a property named Cards, which must return an object which has a numeric indexer (much like an array). often collections are used for this purpose. The return value of this indexer must be an object that exposes a method named GetSuit().

here is a quick demo of how this is possible:

public class Player
{
   private string name;
   private CardCollection cards;

   public Player(string name)
   { 
     this.name = name; 
     this.cards = new CardCollection();
   }

  public CardCollection Cards
  {
    get{ return this.cards; }
  }
}

public class CardCollection : CollectionBase
{
   ... implementation of BaseCollection

   public Card this[int index] 
   {
      get{ return InnerList[index] }
   }
}

public class Card
{

  private int suit;

  ...  implementation of card

  public int GetSuit()
  {
    return this.suit;
  }
}

GeneralRe: Class Inheritance and Propertys Pin
Steini kallinn13-Mar-06 23:32
Steini kallinn13-Mar-06 23:32 
GeneralRe: Class Inheritance and Propertys Pin
J4amieC13-Mar-06 23:53
J4amieC13-Mar-06 23:53 
QuestionConversion from BigEndian to Little Endia Pin
hpetriffer13-Mar-06 21:00
hpetriffer13-Mar-06 21:00 
AnswerRe: Conversion from BigEndian to Little Endia Pin
Divyang Mithaiwala13-Mar-06 21:49
Divyang Mithaiwala13-Mar-06 21:49 
GeneralRe: Conversion from BigEndian to Little Endia Pin
hpetriffer13-Mar-06 21:58
hpetriffer13-Mar-06 21:58 
AnswerRe: Conversion from BigEndian to Little Endia Pin
Steve Hansen13-Mar-06 23:13
Steve Hansen13-Mar-06 23:13 
GeneralRe: Conversion from BigEndian to Little Endia Pin
hpetriffer13-Mar-06 23:17
hpetriffer13-Mar-06 23:17 
GeneralRe: Conversion from BigEndian to Little Endia Pin
Steve Hansen13-Mar-06 23:26
Steve Hansen13-Mar-06 23:26 
QuestionHow to print the dynamic datagrid in web page Pin
angelagke13-Mar-06 20:43
angelagke13-Mar-06 20:43 
AnswerRe: How to print the dynamic datagrid in web page Pin
swap2015-Mar-06 5:26
swap2015-Mar-06 5:26 
GeneralRe: How to print the dynamic datagrid in web page Pin
angelagke15-Mar-06 15:16
angelagke15-Mar-06 15:16 
Questioncontent filtering Pin
Mitra77713-Mar-06 20:36
Mitra77713-Mar-06 20:36 
Questionhow to add scrollbar to my form ? Pin
hdv21213-Mar-06 20:30
hdv21213-Mar-06 20:30 
AnswerRe: how to add scrollbar to my form ? Pin
V.13-Mar-06 22:36
professionalV.13-Mar-06 22:36 
QuestionSocket releted Error Pin
Divyang Mithaiwala13-Mar-06 19:37
Divyang Mithaiwala13-Mar-06 19:37 
QuestionHow to pass commandline Arguements Pin
psmukil13-Mar-06 19:14
psmukil13-Mar-06 19:14 
Questionhow to discover the systems in a network using c# and wmi Pin
barath_chidambaram13-Mar-06 18:17
barath_chidambaram13-Mar-06 18:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.