Witaj w kursie C#!

Od podstaw do zaawansowanych technik. Rozpocznij swoją przygodę z programowaniem w C#.

Zaczynamy! Dokumentacja C# Pobierz Visual Studio Pobierz .Net

Podstawy C#

Zmienne i Typy Danych


int liczba = 10;
string tekst = "Witaj, C#!";
bool prawda = true;
                

Instrukcje warunkowe


if (liczba > 5)
{
    Console.WriteLine("Liczba jest większa niż 5");
}
                

Wczytywanie danych od użytkownika


Console.WriteLine("Podaj swoje imię:");
string imie = Console.ReadLine(); // Wczytuje tekst od użytkownika
Console.WriteLine("Witaj, " + imie + "!");
            

Petle


for (int i = 1; i <= 5; i++)
{
     Console.WriteLine("Numer: " + i);
}                
            

Przykłady Kodów

Program "Hello, World!"


using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Witaj, C#!");
    }
}
                

Program Obliczanie pola prostokąta


using System;

class Program
{
    static void Main()
    {
        // Wczytanie danych od użytkownika
        Console.WriteLine("Podaj długość prostokąta:");
        double dlugosc = double.Parse(Console.ReadLine());
                    
        Console.WriteLine("Podaj szerokość prostokąta:");
        double szerokosc = double.Parse(Console.ReadLine());
                    
        // Obliczanie pola prostokąta
        double pole = dlugosc * szerokosc;
                    
        // Wyświetlenie wyniku
        Console.WriteLine($"Pole prostokąta o bokach {dlugosc} i {szerokosc} wynosi: {pole}");
    }
}
                

Przyklad zmiennych


using System;


class Program
{
    static void Main
    {
        int liczba; //Tworzenie zmiennej
        int liczba = 10; //Nadawanie wartosci zmiennej
        Console.WriteLine(liczba); //Wykorzystywanie zmiennej
    }
}
                

Zaawansowany C#

Refleksja


using System;
using System.Reflection;

class Program
{
    static void Main()
    {
        Type type = typeof(string);
        MethodInfo[] methods = type.GetMethods();

        foreach (var method in methods)
        {
            Console.WriteLine(method.Name);
        }
    }
}
            

Atrybuty


using System;

[AttributeUsage(AttributeTargets.Class)]
class MyAttribute : Attribute
{
    public string Info { get; }
    public MyAttribute(string info) => Info = info;
}

[MyAttribute("Example Class")]
class ExampleClass {}

class Program
{
    static void Main()
    {
        Type type = typeof(ExampleClass);
        var attributes = type.GetCustomAttributes(typeof(MyAttribute), false);
        
        foreach (MyAttribute attr in attributes)
        {
            Console.WriteLine(attr.Info);
        }
    }
}
            

Dynamiczne typy


using System;
using System.Dynamic;

class Program
{
    static void Main()
    {
        dynamic expando = new ExpandoObject();
        expando.Name = "John";
        expando.Age = 30;

        Console.WriteLine($"{expando.Name}, Age: {expando.Age}");
    }
}
            

Unsafe Code i wskaźniki


using System;

class Program
{
    unsafe static void Main()
    {
        int number = 10;
        int* pointer = &number;
        Console.WriteLine($"Value: {number}, Address: {(long)pointer}");
    }
}
            

Task Parallel Library (TPL) i równoległość


using System;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        Task task1 = Task.Run(() => Console.WriteLine("Task 1"));
        Task task2 = Task.Run(() => Console.WriteLine("Task 2"));

        await Task.WhenAll(task1, task2);
    }
}
            

Blokada wielowątkowa


using System;
using System.Threading;

class Program
{
    static object lockObj = new object();

    static void Main()
    {
        Thread t1 = new Thread(Print);
        Thread t2 = new Thread(Print);
        
        t1.Start();
        t2.Start();

        t1.Join();
        t2.Join();
    }

    static void Print()
    {
        lock (lockObj)
        {
            Console.WriteLine("Thread: " + Thread.CurrentThread.ManagedThreadId);
            Thread.Sleep(1000);
        }
    }
}
            

Praca z plikami i strumieniami


using System;
using System.IO;

class Program
{
    static void Main()
    {
        using (FileStream fs = new FileStream("example.txt", FileMode.Create))
        using (StreamWriter writer = new StreamWriter(fs))
        {
            writer.WriteLine("Hello, File!");
        }
    }
}                
            

Kursy

Kurs 1: Wprowadzenie do C#

Poznaj podstawy C#, w tym zmienne, typy danych i składnię. Kurs ten da ci podstawy, które pozwolą na rozpoczęcie programowania w C#.

Kurs 2: Funkcje w C#

Kurs ten koncentruje się na funkcjach w C#. Nauczysz się, jak deklarować funkcje, przekazywać parametry i zwracać wartości.

Kurs 3: Zaawansowany C#

W tym kursie zagłębimy się w zaawansowane tematy C#, takie jak LINQ, async/await i inne.

Kurs 4: Stylowanie CSS

Kurs ten wprowadza do CSS (Cascading Style Sheets). Nauczysz się, jak stylizować elementy HTML, zmieniać kolory i układ strony.