how to store multiple string value in one int variable
string OutReader = ConfigurationManager.AppSettings["OutReader"].ToString();
int outrdr = Convert.ToInt32(OutReader);
The value of AppSettings["OutReader"]
is: "(1,2)"
how to store multiple string value in one int variable
string OutReader = ConfigurationManager.AppSettings["OutReader"].ToString();
int outrdr = Convert.ToInt32(OutReader);
The value of AppSettings["OutReader"]
is: "(1,2)"
If AppSettings["OutReader"]
currently have in it a string like: "(1,2)"
then you can do:
var sections = ConfigurationManager.AppSettings["OutReader"].Replace("(",string.Empty)
.Replace(")",string.Empty)
.Split(',');
if(sections.Length > 0)
{
int outrdr = Convert.ToInt32(sections[0]);
}
This can still throw an exception in the case that section[0]
can't be parsed into an int
so use .TryParse
instead - Just wanted to stay as close to the question as possible