学习foreach

    技术2022-05-11  64

    using  System; public   class  Foreach1 {    static void Main()    {        int [] values={5,6,7,8};            foreach (int i in values)                Console.WriteLine("the number is {0}",i);                //Console.WriteLine("the number is {0}",values[i]);注意两者的不同        string myString="this is a string";        char[] myChars=myString.ToCharArray();        foreach (char character in myString)        {            Console.Write("{0} ",character);        }        Console.WriteLine();                char[] separator={' '};        string[] myWords;        myWords=myString.Split(separator);        foreach (string word in myWords)        {            Console.Write("{0},",word);        }    }} D:Projecthanding > Foreach1the number  is   5 the number  is   6 the number  is   7 the number  is   8 t h i s   i s   a   s t r i n g this , is ,a, string ,

    最新回复(0)