Tech Off Post

Single Post Permalink

View Thread: C# dice Roller
  • User profile image

    I haven't tried your code, but the approach looks reasonable. 

    I'd move the "new Random()" call before the "for" loop; creating a new one every time is just wasting time.

    The string constructions at the end (with .Clone and casting to a string[]) seems a little wacky to me.  I'd just accumulate the dice roll string inside the for loop; on each loop add the current roll to the end of the string, and then tack the total on after the loop exits.

    There are a bunch of "coding style" things I'd do differently, but they don't effect functionality so I'll leave them alone.

    Let me know if memory size or program speed are important; for this application I assume they are not, if they are there are other things you can do to improve the code.  (Such as using StringBuilder as someone else suggested.)