首页 > 解决方案 > 经常打印“-”字符有多长

问题描述

我在我自己的小程序中工作,所以我想问我如何才能进行变量测试以给出 - 这么长的 intro.Length 是多少。

所以字符串介绍是 66 个字符,空间长现在我希望它只打印 - 66 次,如 ----------------------------- ----------------- 但是 66 个字符长我该怎么做?

using System;

namespace ConsoleApp1
{
    class Program
    {
        public static int alter;
        public static string vorname;
        public static string nachname;
        public static string jeah;
        public static string intro;
        public static int abc;
        public static string test;

        static void Main(string[] args)
        {
            intro = "Hey you wanna try my small Program? If Yes enter Y if not enter N!";
            abc = intro.Length;
            test = "-" * ;

            Console.Write(test);
            jeah = Console.ReadLine();
            if (jeah == "Y")
            {
                Vorname();
                Nachname();
                Alter();
                Output();
            } else
            {
                Console.WriteLine("Schade dann nicht!");
            }

            
            Console.ReadKey();
        }

标签: c#

解决方案


As simple as using the string's constructor like this :

string s = new string('-', 66);

推荐阅读