I have the following foreach loop in a c# project which loops through list items and it limits it to only show 3
And in my
What I need to do is replace th in the key instead.
I'm guessing it's meant to be
I have the following foreach loop in a c# project which loops through list items and it limits it to only show 3
And in my
What I need to do is replace th in the key instead.
I'm guessing it's meant to be
To access App/Web.config you can use ConfigurationManager
:
int value = (int)System.Configuration.ConfigurationManager.AppSettings["TrendingNavLimit"];
Please follow that article for more details: https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager(v=vs.110).aspx
If we put it all together, solution could be:
int value = (int)ConfigurationManager.AppSettings["TrendingNavLimit"];
foreach (NavigationItem item in items.Take(value))
{
@NavigationHelper.SimpleNavLink(config, item, absoluteUrls);
}
In terms of SOLID, I would re-thing approach though.
I would create an interface
- IConfigProvider
with property TrendingNavLimit {get;}
and implement that interface
in default class, that will use ConfigurationManager
to retrieve data, and then inject it in you class.