学习foreach

来源:互联网 发布:公司财务战略矩阵 编辑:程序博客网 时间:2024/05/01 16:08
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
>Foreach1
the 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,
原创粉丝点击