The code you specified will not add anything extra to the line. Perhaps this is how you copy and paste what causes the problem. If this sometimes causes a problem, look at the HTML source (right-click, “View Source”) and see if you see the problem there.
EDIT: As Henk found out, your code apparently doesn't seem so. How did you end up with a weird symbol in your source code?
Having said that, I would definitely change my code:
- I would name this name according to the .NET naming conventions.
- I would use
Random as a parameter, so you can call it several times in a row without creating the same line several times - I would create a char array of the desired length, populate it, and then create a new string, instead of using string concatenation
- I would create a string length to generate and possibly even character set options.
Just to give an idea of how this would look: in this example, I did not turn the character set into a parameter, but I extracted it from the method:
private const string ValidCharacters = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; public static string GenerateString(Random random, int length) {
source share