小编use*_*032的帖子

在C#中更容易输出Char输出?

是否有更简单的方法以交替的顺序输出X 8次O?所以它最终看起来像这个"XOXOXOXO".我的意思是这个有效,但它的丑陋.谢谢.

        char x = "X" [0];
        char o = "O" [0]; 

        Console.WriteLine("Should X or O go first: ");
        String answer = Console.ReadLine ();



            if (answer == "x") {


            for( int a = 0; a < 4; a++) {

                Console.WriteLine("{0}{1}{2}{3}{4}{5}{6}{7}", x, o, x, o, x, o, x, o);
                Console.WriteLine("{0}{1}{2}{3}{4}{5}{6}{7}", o, x, o, x, o, x, o, x);

                } 
Run Code Online (Sandbox Code Playgroud)

c#

1
推荐指数
3
解决办法
145
查看次数

用户输入存储在方法中

我遇到方法有问题.因此,在一个方法中,我向用户询问名字,我想将该String存储在另一个方法中,然后让我的main方法调用存储String的方法.但是我在存储该字符串时遇到了麻烦.我正在使用此代码:

static void GetStudentInformation()
{
    Console.WriteLine("Enter the student's first name: ");
    string firstName = Console.ReadLine();
}

static void PrintStudentDetails(string first)
{
    Console.WriteLine("{0}", first);
}

public static void Main (string[] args){
    GetStudentInformation();
}
Run Code Online (Sandbox Code Playgroud)

因此,一旦输入名称,它应该存储在详细信息方法中,然后在main方法中调用.谢谢你提前帮助我.

c#

0
推荐指数
1
解决办法
2027
查看次数

标签 统计

c# ×2