ASP.NET Sayısal Loto Örneği

sdkbyrm

webmasterfrm
Üyelik Tarihi
23 Aralık 2020
Mesajlar
813
Beğeniler
1
Ticaret: 0 / 0 / 0
Bu örneğimizde ASP.NET ile C# Generic Collection kullanılarak bir Sayısal Loto uygulaması oluşturacağız. Butona basıldığında 1-49 arası 6 adet rastgele sayı üreterek sıralı bir şekilde eklediğimiz Label kontrollerinde göstereceğiz.


Form tasarımımız:
1608737466276.png
Default.aspx tasarım kodlarımız:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 47%;
}
.auto-style2 {
width: 101px;
}
.auto-style3 {
width: 98px;
}
.auto-style4 {
width: 96px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>

<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="XX-Large" Text="Label"></asp:Label>
</td>
<td class="auto-style2">
<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Size="XX-Large" Text="Label"></asp:Label>
</td>
<td class="auto-style3">
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="XX-Large" Text="Label"></asp:Label>
</td>
<td class="auto-style4">
<asp:Label ID="Label4" runat="server" Font-Bold="True" Font-Size="XX-Large" Text="Label"></asp:Label>
</td>
<td class="auto-style4">
<asp:Label ID="Label5" runat="server" Font-Bold="True" Font-Size="XX-Large" Text="Label"></asp:Label>
</td>
<td>
<asp:Label ID="Label6" runat="server" Font-Bold="True" Font-Size="XX-Large" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td colspan="6">
<asp:Button ID="Button1" runat="server" Font-Size="XX-Large" OnClick="Button1_Click" Text="OYNA" Width="247px" />
</td>
</tr>
</table>

</div>
</form>
</body>
</html>


Default.aspx.cs C# kodlarımız:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

protected void Button1_Click(object sender, EventArgs e)
{
Random rnd = new Random();
List<int> sayilar = new List<int>();
List<int> tahmin = new List<int>();
for (int i = 1; i <= 49; i++)
{
sayilar.Add(i);
}
for (int x = 1; x <= 6; x++)
{

int index = rnd.Next(0, sayilar.Count);
tahmin.Add(sayilar[index]);
sayilar.RemoveAt(index);
}
tahmin.Sort();
Label1.Text = tahmin[0].ToString();
Label2.Text = tahmin[1].ToString();
Label3.Text = tahmin[2].ToString();
Label4.Text = tahmin[3].ToString();
Label5.Text = tahmin[4].ToString();
Label6.Text = tahmin[5].ToString();
}


Ekran çıktısı aşağıdaki şekilde olacaktır.
1608737479919.png
 
Üst