public string Weird
{
get
{
int length = 10;
Random random = new Random();
string chars = "123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXZ";
StringBuilder builder = new StringBuilder(length);
for (int i = 0; i < length; i++)
{
builder.Append(chars[random.Next(chars.Length)]);
}
return builder.ToString();
}
}
Response.Write(Weird);
Response.Write("<br />");
Response.Write(Weird);
Response.Write("<br />");
Response.Write(Weird);
Result :
9eFZ5XrJxZ
9eFZ5XrJxZ
9eFZ5XrJxZ
我认为每次调用的结果都会不同,但它返回相同的结果值。怎么可能?一旦分配了变量,那么get方法将不会再次运行?