0

我不知道如何以另一种方法访问我的实例。我有这组代码。

Card rorbcard = new Card();
        Deck deck = new Deck();
        deck.Shuffle();
        rorbcard = deck.TakeCard();
        Start0:
        Console.Clear();
        Console.WriteLine("Allright lets play! Red or black?");
        string userValue0 = Console.ReadLine();
        switch (userValue0.ToLower())
        {
            case "red":
                {
                    if (rorbcard.Suit.Equals(Suit.Diamonds))
                        {
                            Console.WriteLine("{0},\n Correct give 2 drinks",
                          rorbcard.ToString());
                            Thread.Sleep(2000);
                        }
                    else if (rorbcard.Suit.Equals(Suit.Hearts))
                    {
                        Console.WriteLine("{0},\n Correct give 2 drinks",
                        rorbcard.ToString());
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        Console.WriteLine("{0},\n Wrong sucka take 2 drinks",
                        rorbcard.ToString());
                        Thread.Sleep(2000);
                    }
                }

我正在尝试在另一种方法中使用该 rorbcard.ToString() ,但我不知道如何引用它。这是另一种方法。

 public void HighLow()
    {
        //highlow part of the game
        Deck deck = new Deck();
        deck.Shuffle();
        Card highLow = new Card();
        highLow = deck.TakeCard();
    Start1:
        Console.Clear();
        Console.WriteLine("Your Hand:");
        Grid.WriteAt(rorbcard.ToString(), 0, 1);
        Console.WriteLine("\n\nDo you think that the next card will higher,lower,\n or
        equal to the {0}. Enter high, low, or equal\n", rorbcard);
        string uservalue1 = Console.ReadLine();
        switch (uservalue1.ToLower())
        {
            case "high":

                if (highLow.CardNumber > rorbcard.CardNumber)  <-----Issue
                {
                    Console.WriteLine("{0},\n Correct give 4 drinks",
                    highLow.ToString());
                    Thread.Sleep(2000);
                }
                else
                {
                    Console.WriteLine("{0},\n Wrong  drink 4\n", highLow.ToString());
                    Thread.Sleep(2000);
                }

感谢您花时间调查此事。我被困住了一段时间。

4

2 回答 2

1

你可以做

一个。作为参数传递给HighLow()喜欢

public void HighLow(string rorbcard)

湾。创建一个类级别变量。为其赋值并使用该HighLow()

class MyClass
{
    private string rorbCardClassLevel;

    private void MyrorbCardMethod
    {
        //Other code lines.

        //Inside case statement
        rorbCardClassLevel = rorbcard.ToString();
    }

    private void HighLow()
    {
        //Use rorbCardClassLevel here.            
    }
}
于 2013-10-19T00:29:26.557 回答
0

我需要做的就是将我的实例放在方法之外和我的类中。呵呵

于 2013-10-21T19:29:17.487 回答