环境:Vs2022
1、添加App.config文件
添加key和value
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="connectionString" value="server=.;database=School;uid=sa;pwd=123"/>
</appSettings>
</configuration>
添加引用
命名空间:System.Configuration
程序集: System.Configuration.dll,通过nuget 包引用
C# 类库中引用字符串格式:
string connectionString = ConfigurationManager.AppSettings["connectionString"];