Creating an object containing an array and int - small error
Hi,
I am writing a black jack program and have created an object containing an array if ints (the players hand) and one other int value (the dealers faced up card). But when i try to create an instance of the object, i seem to be declaring it wrong. Here is my code. on the last line 'hand []' is underlined showing 'The type of the expression must be an array type but it resolved to CreateHand'
public class CreateHand {
int cardA = 0;
int cardB = 0;
int dealersCard;
int [] hand = {cardA, cardB};
public CreateHand(int [] hand1, int dCard){
hand = hand1;
dealersCard = dCard;
}
public CreateHand Start(){
CreateHand hand = new CreateHand(hand [],dealersCard); // hand [] has a syntax error!
code continues .......
iv tired 'hand' , '[] hand' and 'hand[]'..... any ideas where i am going wrong?
Many Thanks
Re: Creating an object containing an array and int - small error
You don't use the type of a variable when using that variable as an argument to a method. Just use the name of the variable: hand
leave off the []s
Re: Creating an object containing an array and int - small error
thanks for that. I tried 'hand' on its own but it still didn't like it. I played around with it a bit and found that the object was also called 'hand' and they couldn't be the called the same name.
Thanks for your help
Re: Creating an object containing an array and int - small error