string[] values = { "12,3", "45", "ABC", "11", "DEF" };
decimal total = 0;
string msg = "";
foreach (string value in values)
{
decimal parsedValue;
if (decimal.TryParse(value, out parsedValue))
{
total += parsedValue;
}
else
{
msg += value;
}
}
Console.WriteLine($"Total: {total}");
Console.WriteLine($"Message: {msg}");
string[] values = { "12,3", "45", "ABC", "11", "DEF" };
decimal total = 0;
string msg = "";
foreach (string value in values)
{
decimal parsedValue;
if (decimal.TryParse(value, out parsedValue))
{
total += parsedValue;
}
else
{
msg += value;
}
}
Console.WriteLine($"Total: {total}");
Console.WriteLine($"Message: {msg}");