您的位置:首页 > 其它

简单基础操作,字符串操作,循环等

2016-07-24 23:02 399 查看
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace test

{

    class Program

    {

        static void Main(string[] args)

        {

            int i = 1;

            object o = i;//装箱

            int j = (int)o;//拆箱

            //Console.WriteLine(j);

            //插入字符串

            string str = "This is a girl.";

            str = str.Insert(10, "buautiful ");

            Console.WriteLine(str);

            //填充字符PadLeft串

            string str1 = "Hello World!";

            string  strleft = str1.PadLeft(15, '@');

            string strright = str1.PadRight(15, '@');

            Console.WriteLine(strleft + " " + strright);

            Console.WriteLine("----------while");

            int n = 1;

            while (n <= 8) 

            {

                Console.Write(n); n++; 

            }

            Console.WriteLine("");

            Console.WriteLine("----------do while");

            int b = 1;

            do

            {

                Console.Write(b); b++;

            }

            while (b <= 8);

            Console.WriteLine("");

            Console.WriteLine("----------数组");

            //数组

            int[] arr = new int[8]{1,2,3,4,5,6,7,8};

            foreach (int item in arr)

            {

                Console.Write(item);

            }

            Console.WriteLine("");

            Console.WriteLine("----------二维数组for遍历");

            int[,] array = new int[,] { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 } };

            for (int g = 0; g < 4; g++)//行的行数

            {

                for (int h = 0; h < 2; h++)//行的列数

                {

                    Console.Write(array[g, h] + "\t");

                }

                Console.WriteLine();

            }

            Console.WriteLine("----------二维数组foreach遍历");

            foreach (int q in Enumerable.Range(0, array.GetLength(0)))

            {

                foreach (int w in Enumerable.Range(0, array.GetLength(1)))

                {

                    Console.Write(array[q, w] + " ");

                }

                Console.Write("\n");

            }

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: