Parsing config strings manually is error-prone. GetValue
Manual Parsing (Error-Prone):
// appsettings.json: "MaxRetries": "3" var maxRetries = int.Parse(_config["MaxRetries"]); // NullReferenceException if key missing! // FormatException if value is not a number!
Type-Safe GetValue:
var maxRetries = _config.GetValue("MaxRetries", defaultValue: 5); // Returns 3 if exists // Returns 5 if missing or invalid // No exceptions!
Works With Any Type:
var isEnabled = _config.GetValue("Features:NewUI"); var timeout = _config.GetValue ("Timeout"); var url = _config.GetValue ("ApiUrl"); var price = _config.GetValue ("Price", 9.99m);
Safe, clean, with defaults!




