C Sharp: Różnice pomiędzy wersjami

[wersja nieprzejrzana][wersja nieprzejrzana]
Usunięta treść Dodana treść
NotroDev (dyskusja | edycje)
m Aktualizacja aktualnej wersji stabilnej
NotroDev (dyskusja | edycje)
Zmodyfikowanie przykładu, aby korzystał z najnowszych funkcji języka.
Linia 265:
</syntaxhighlight>
 
Inny program symulujący uniwersalną kostkę do gry, można w nim zobaczyć kilka podstawowych instrukcji języka C# oraz wykorzystanie funkcji [https://learn.microsoft.com/pl-pl/dotnet/csharp/fundamentals/program-structure/top-level-statements instrukcji najwyższego poziomu].
<syntaxhighlight lang="csharp" line="1">
int kostka;
using System;
Random liczba = new Random();
 
string strinput = Stringstring.Empty;
public class Kostka
Console.Clear();
while (true)
{
Console.Write("Iluścienną kostką chcesz grać? ");
public static void Main()
{try
{
int kostka = 0int.Parse(Console.ReadLine());
Random liczba = new Random();
string str = String.Empty;
Console.Clear();
while (true)
{
Console.Write("Iluścienną kostką chcesz grać? ");
try { kostka = int.Parse(Console.ReadLine()); }
catch
{
Console.WriteLine("Podano nieprawidłowe dane!");
kostka = 0;
}
if (kostka < 4) { Console.WriteLine("Kostka ma minimum 4 ściany."); }
else break;
}
Console.Clear();
while (!str.Equals("q"))
{
Console.WriteLine($"Wylosowana liczba to: {liczba.Next(kostka) + 1}\tAby zakończyć wciśnij Q + Enter");
str = Console.ReadLine();
}
}
catch
{
Console.WriteLine("Podano nieprawidłowe dane!");
kostka = {0;
}
if (kostka =< 0;4)
{
if (kostka < 4) { Console.WriteLine("Kostka ma minimum 4 ściany."); }
}
else break;
}
Console.Clear();
while (!strinput.Equals("q"))
{
Console.WriteLine($"Wylosowana liczba to: {liczba.Next(kostka) + 1}\tAby zakończyć wciśnij Q + Enter");
try { kostkainput = int.Parse(Console.ReadLine()); }
}
</syntaxhighlight>