score:13

Accepted answer

if you don't care which characters then you could just use the string constructor:

string s = new string('0', 500);

this will give you a string with 500 "0"s. or for 500 x's:

string s = new string('x', 500);

score:0

new string(enumerable.range(0,500).selectmany(x => x.tostring()).take(500).toarray())

simplest way with linq. since a string is technically an enumerable (char[]), you can use selectmany (which takes multiple enumerables and flattens into a single collection) followed by a take(500) to only get 500 characters, call toarray to get a char[] to instantiate a new string.

score:0

one more option, not quite the requested output from the original question - digits are random rather than increasing - but fairly succinct (i know, the op didn't require a string of random digits but here's one in any case).

var rand = new random();
string.join("",enumerable.repeat(0, 500).select(i => rand.next(10)));

score:1

this should do the trick.

var range = new string(string.concat(enumerable.range(0, 500)
                                               .select(c => c.tostring()))
                             .take(500).toarray()
                      );

score:1

linq is nifty, but you don't always need it...:

static string numstring(int length) {
    var s = "";
    var i = 0;
    while (s.length < length) {
        s += i.tostring();
        i++;
    }
    return s.substring(0, length);
}

or a variant using aggregate:

var str = enumerable.range(0, 500)
          .aggregate("", (s, next) => s += next.tostring(), 
                         s => s.substring(0, 500));

score:2

you want to use aggregate:

  string range = enumerable.range(0,500)
                .select(x => x.tostring()).aggregate((a, b) => a + b);
  console.writeline(range);

this will give you a string of concatenated numbers from 0 to 500. like this: 01234567891011121314151617...
if you need to take 500 chars from this big string, you can further use substring.

string range = enumerable.range(0,500)
              .select(x => x.tostring()).aggregate((a, b) => a + b);
console.writeline(range.substring(0, 500));

Related Query

More Query from same tag