randomGenerator
刚才在看ASP.NET 快速入门教程时有看到这么一段代码。对里面的随机方面的代码不是很清楚。这个暂时还不是自己学习的重点,近期不去钻研。
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E) {
Random randomGenerator = new Random(DateTime.Now.Millisecond);
int randomNum = randomGenerator.Next(0, 3);
switch(randomNum) {
case 0:
Name.Text = "Scott";
break;
case 1:
Name.Text = "Fred";
break;
case 2:
Name.Text = "Adam";
break;
}
AnchorLink.NavigateUrl = "controls_navigationtarget_cs.aspx?name=" + System.Web.HttpUtility.UrlEncode(Name.Text);
}
</script>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E) {
Random randomGenerator = new Random(DateTime.Now.Millisecond);
int randomNum = randomGenerator.Next(0, 3);
switch(randomNum) {
case 0:
Name.Text = "Scott";
break;
case 1:
Name.Text = "Fred";
break;
case 2:
Name.Text = "Adam";
break;
}
AnchorLink.NavigateUrl = "controls_navigationtarget_cs.aspx?name=" + System.Web.HttpUtility.UrlEncode(Name.Text);
}
</script>