Say you have an enumerated type
var digits = [1, 2, 3 ...];
then you can do:
// simplest and correct way; essentially the accepted answer but using LINQ var number = digits.Aggregate((a, b) => a * 10 + b); // string manipulation; works for sets like [10, 20, 30] var number = int.Parse(string.Join("", digits)); // using `Select` instead of `Aggregate` but verbose; not very useful var number = (int)digits.Select((d, i) => d * Math.Pow(10, digits.Count() - i - 1)).Sum();
nawfal
source share