c# - Call a string method from one class to another -


i have assignment based on coin , card games simplified. given complete , incomplete files. trying invoke method (which string) 1 class (card.cs) in (hand.cs).

here string method card.cs:

public string tostring(bool shortformat, bool displaysuit)     {         string returnstring;          // describe facevalue.         facevalue facevalue = getfacevalue();         string facevalueasstring = facevalue.tostring();         if (shortformat) {             if (facevalue <= facevalue.ten) {                 facevalueasstring = (facevalue - facevalue.two + 2).tostring();             } else {                 facevalueasstring = facevalueasstring.substring(0, 1);             }         }          returnstring = facevalueasstring;          // describe suit.         if (displaysuit) {             string suit = getsuit().tostring();             if (shortformat) {                 suit = suit.substring(0, 1);                 returnstring += suit;             } else {                 returnstring += " of " + suit;             }         }          return returnstring;     } 

and hand.cs (the tostring string/method only, there other functions in file deal creating hand (list named cards) , adding cards it.)

/// <summary>     /// outputs hand of cards.     /// see tostring method in card class description of      /// 2 parameters: shortformat , displaysuit.     /// pre: true     /// post: displayed hand of cards.     /// </summary>     public void displayhand(bool shortformat, bool displaysuit) {          //         //**************** code needs added**********************         // should able call tostring method in card class,         // part of this.         //      } // end displayhand 

they unedited files got assignment. want know how use twostring(shortformat, displaysuit) in displayhand(shortformat, displaysuit). @ 1 stage had separate list put string values in, since got deleted trying revert files original. not quite sure how going used later in game, figured if functioning list, changing list string or array or whatever done quite later. once know how call string should able modify code other strings , integers have call.

you need card call tostring on. assume this:

foreach (card card in this.cards) { ... } // loop through cards in hand. 

i can't tell how without seing code.

once have card (in card variable), call tostring this:

string str = card.tostring(true, true); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -