What is App.config in C#.NET? How to use it?

前端 未结 6 1972
情深已故
情深已故 2020-11-22 15:00

I have done a project in C#.NET where my database file is an Excel workbook. Since the location of the connection string is hard coded in my coding, there is no problem for

6条回答
  •  旧时难觅i
    2020-11-22 15:45

    Simply, App.config is an XML based file format that holds the Application Level Configurations.

    Example:

    
    
      
        
      
    
    

    You can access the configurations by using ConfigurationManager as shown in the piece of code snippet below:

    var value = System.Configuration.ConfigurationManager.AppSettings["key"];
    // value is now "test"
    

    Note: ConfigurationSettings is obsolete method to retrieve configuration information.

    var value = System.Configuration.ConfigurationSettings.AppSettings["key"];
    

提交回复
热议问题