using System;
class MainClass
{
public static void Main()
{
int odd = 0, even = 0;
int[] arr = new int [] {0,1,2,5,7,8,11};
foreach (int i in arr) //遍历数组中数据
{
if (i%2 == 0) //如果为偶数,则偶数个数加一
even++;
else
odd++; //否则奇数个数加一
}
Console.WriteLine("Found {0} Odd Numbers, and {1} Even Numbers.",
odd, even) ;//写出偶数,奇数个数
}
}
[此贴子已经被作者于2006-1-10 10:49:24编辑过]
using System.Data;
using System.Data.SqlClient;
public class readData
{
public static void Main()
{
SqlConnection con=new SqlConnection(....);
SqlCommand cmd=new SqlCommand();
cmd.Connection=con;
cmd.CommandText="....";
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cmd;
DataSet ds=new DataSet();
da.Fill(ds);
foreach(DataRow r in ds.Tables[0].Rows)
{
Console.WriteLine(r.ToString());
}
}
}