I'm some what embarrassed to even ask this but I know there is a better way to do this I just don't know how
List<int> numbers = new List<int>(22);
numbers.Add(3);
numbers.Add(4);
numbers.Add(9);
numbers.Add(14);
numbers.Add(15);
//...
List<int> numbers = new List<int>(22) { 3, 4, 9, ..., 99 };
shorter than that? Only if your numbers follow a pattern which could be expressed mathematically.
This is the collection initializer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With