首頁 App.Config Set Key And Value
文章
Cancel

App.Config Set Key And Value

appSettings

在App.Config的檔案裡面,可以在configuration裡面加入appSettings,然後在appSettings裡面新增所需的Key And Value的Config

App.Config

1
2
3
4
5
<configuration>
    <appSettings>
      <add key="SetKey" value="I am Value" />
    </appSettings>
</configuration>

在C#裡面可以這樣調用上方App.Config的appSettings的資料

Program.cs

1
string AppSetting = ConfigurationManager.AppSettings["SetKey"];

connectionString

ConnectString設定與讀取的方式如下,基本上與上方的appSettings差不多

App.Config

1
2
3
4
5
<configuration>
  <connectionStrings>
      <add name="MSSQL" connectionString=" " providerName="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>

Program.cs

1
 string strConnectString = ConfigurationManager.ConnectionStrings["MSSQL"].ConnectionString;
本文由作者按照 CC BY 4.0 進行授權