关闭

C# app.config read values

273人阅读 评论(0) 收藏 举报

请注意引用using System.Configuration;

using System;
using System.Data;
using System.Net;
using System.Windows.Forms;
using System.Configuration;

namespace TY.Kanban.Prod
{
    public partial class Kanban_Prod_A : Form
    {
        public Kanban_Prod_A()
        {
        }

        private void Kanban_Prod_A_Load(object sender, EventArgs e)
        {
              }

        private void GetConnectionStrings()
        {
            string str = System.Configuration.ConfigurationManager.AppSettings.GetValues("pw")[0];
            this.Text = str;
        }

        static void DisplayAppSettings()
        {

            try
            {

                AppSettingsReader reader = new AppSettingsReader();


                NameValueCollection appSettings = ConfigurationManager.AppSettings;

                for (int i = 0; i < appSettings.Count; i++)
                {
                    Console.WriteLine("Key : {0} Value: {1}",
                      appSettings.GetKey(i), appSettings[i]);
                }

            }
            catch (ConfigurationErrorsException e)
            {
                Console.WriteLine("[DisplayAppSettings: {0}]", e.ToString());
            }

        }

}
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:221294次
    • 积分:4115
    • 等级:
    • 排名:第7774名
    • 原创:61篇
    • 转载:192篇
    • 译文:0篇
    • 评论:6条
    最新评论