Назад Вперед Зміст

Спеціальні методи

1. Методи розширення

public static class StringExtensions
{
    public static bool IsNullOrEmpty(this string str)
    {
        return string.IsNullOrEmpty(str);
    }
}

// Використання:
string text = "";
var isEmpty = text.IsNullOrEmpty();

2. Перевантаження методів

public class Printer
{
    public void Print(string text)
    {
        Console.WriteLine(text);
    }

    public void Print(string text, int count)
    {
        for (int i = 0; i < count; i++)
            Console.WriteLine(text);
    }
}

Назад Вперед Зміст