C Profile Action Class Sharing

  • 2021-12-21 04:42:49
  • OfStack

C # configuration file operation class, for your reference, the specific contents are as follows

Note the addition of references: System. Configuration;


using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Configuration; 
 
namespace DotNet.Utilities. Profile action class  
{ 
 public class ConfigHelper_sufei 
 { 
  /// <summary> 
  ///  According to Key Take Value Value  
  /// </summary> 
  /// <param name="key"></param> 
  public static string GetValue(string key) 
  { 
   return ConfigurationManager.AppSettings[key].ToString().Trim(); 
  } 
 
  /// <summary> 
  ///  According to Key Modify Value 
  /// </summary> 
  /// <param name="key"> To modify Key</param> 
  /// <param name="value"> The value to modify to </param> 
  public static void SetValue(string key, string value) 
  { 
   ConfigurationManager.AppSettings.Set(key, value); 
  } 
 
  /// <summary> 
  ///  Add a new Key  , Value Key-value pair  
  /// </summary> 
  /// <param name="key">Key</param> 
  /// <param name="value">Value</param> 
  public static void Add(string key, string value) 
  { 
   ConfigurationManager.AppSettings.Add(key, value); 
  } 
 
  /// <summary> 
  ///  According to Key Delete an item  
  /// </summary> 
  /// <param name="key">Key</param> 
  public static void Remove(string key) 
  { 
   ConfigurationManager.AppSettings.Remove(key); 
  } 
 } 
} 

Related articles: