关于#c##的问题,请各位专家解答!

关于#c##的问题,请各位专家解答!

问题描述:

输入一串数字,要求输出这些数字,并且每三个数字之间用“.”隔开。(要求使用foreach结构)

有帮助麻烦点个采纳【本回答右上角】,谢谢~~有其他问题可以继续交流~

img


using System;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var index = 0;
            var ns = "";
            foreach (var c in s) {
                if (index>0&& index % 3 == 0) ns += ".";
                ns += c;
                index++;
            }
            Console.WriteLine(ns);
            Console.ReadKey();
        }
    }
}