zoukankan      html  css  js  c++  java
  • C#编码规范

    1、连接数据库并返回DataTable

       

    View Code

    public DataTable GetDataByTable()
    {
    DataSet dataset = new DataSet();
    DataTable datatable = null;
    SqlConnection sqlConnection = new SqlConnection("Data Source=.;Initial Catalog=Calamity_Data;Integrated Security=True");
    try
    {
    SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select top 50 * from calamity", sqlConnection);
    sqlDataAdapter.Fill(dataset, "calamity");
    if (dataset != null && dataset.Tables.Count > 0)
    {
    datatable = dataset.Tables[0];
    }
    }
    catch (Exception e)
    {
    }
    finally
    {
    sqlConnection.Close();
    }
    Console.WriteLine("Calling WCF Service,Transfer data using DataTable");
    return datatable;
    }

    2、连接数据库文件的相对路径

    SqlConnection sqlConnection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database\\DatabaseWCF.mdf;Integrated Security=True;User Instance=True");
    							

    3、数组

    交叉数组

    for实现 

    int[][] arri = new
    								int[3][];
    arri[0] = new int[] { 1, 2 };
    arri[1] = new int[] { 3 };
    arri[2] = new int[] { 4, 5, 6 };
    int rlen=arri.Length;
    for (int i=0; i < rlen; i++)
    {
    int clen = arri[i].Length;
    for (int j = 0; j < clen; j++)
    {
    Console.WriteLine(arri[i][j]);
    }
    }
    Console.Read();

    foreach实现

    foreach (int[] i in arri)
    {
    foreach (int j in i)
    {
    Console.WriteLine(j);
    }

    }
    Console.Read();

    二维数组

    View Code

    int[,] arri = new
    								int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 } };
    int rlen = arri.GetLength(0);//行数
    int clen = arri.GetLength(1);//列数

    for (int i = 0; i < rlen; i++)
    {
    for (int j = 0; j < clen; j++)
    {
    Console.WriteLine("第{0}行{1}列,值为{2}", i, j, arri[i, j]);
    }
    }
    Console.Read();

    运行结果:

    List应用

  • 相关阅读:
    (转) hive调优(2)
    (转)hive调优(1) coding调优
    hive on tez 错误记录
    tez 0.9.0 配置
    hive on tez
    让博客园自动生成目录
    hive --metastore三种模式
    hive 使用beelin连接报错
    mysql my.cnf文件
    1、Kfaka 部署
  • 原文地址:https://www.cnblogs.com/sjllef/p/1997531.html
Copyright © 2011-2022 走看看