---
title: "Using values from AppConfig file in C#"  
description: "Using values from AppConfig file in C#"  
author: "Samuel Fernandes"  
published: 2014-01-28  
updated: 2014-01-29  
canonical: https://www.mindstick.com/forum/1904/using-values-from-appconfig-file-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Using values from AppConfig file in C#

[selenium](https://www.mindstick.com/blog/11349/fitnesse-vs-selenium) = new DefaultSelenium(

[ConfigurationManager.AppSettings](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why)["TestMachine"].ToString(),

4444,

ConfigurationManager.AppSettings["[Browser](https://www.mindstick.com/blog/155254/which-is-the-best-internet-browser)"].ToString(),

ConfigurationManager.AppSettings["[URL](https://www.mindstick.com/forum/436/url-redirection)"].ToString()

);

Is there an [efficient](https://www.mindstick.com/articles/33637/three-tips-for-an-energy-efficient-home-for-2019) way to do this, [instead of](https://www.mindstick.com/articles/330/triggers-in-sql-server) repeating:

ConfigurationManager.AppSettings[""].ToString()

## Replies

### Reply by Pravesh Singh

Hi Samuel,

I think a better idea is to write a wrapper class to everything that deals with configuration, especially if you write tests. A simple example might be:

```
public interface IConfigurationService{    string GetValue(string key);}
```

This approach will allow you to mock your configuration when you need it and reduce complexity

So you could proceed with:

```
public void SelTest(IConfigurationService config){    var selenium = new DefaultSelenium(config.GetValue("TestMachine"),        4444, config.GetValue("Browser"), config.GetValue("URL"));}
```

or you could inherit your configuration from a List and reduce the typing to:

config["Browser"]


---

Original Source: https://www.mindstick.com/forum/1904/using-values-from-appconfig-file-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
