I think this will be a simple question. I have an App.config that contains a path
<appSettings>
<add key="Path" value="C:\\Test\\" />
</appSettings>
I want to add a couple more paths to the App.config so I don't have them hard coded in my C# windows service. Will it work if I change this
string newPath = @"C:\SecondTest\" + fileName;
to this
string newPath = ConfigurationManager.AppSettings["SecondPa开发者_运维技巧th"] + fileName;
I could then create SecondPath in the App.config.
Yes, it will work but it would be better to combine paths like this instead of using string concatenations:
string newPath = Path.Combine(
ConfigurationManager.AppSettings["SecondPath"],
fileName
);
Yes that would work (did you try it ?).
AppSettings works like key-value storage so it will work however you like
精彩评论