Skip to content

CSharp Keyword sbyte

Codex edited this page Oct 11, 2026 · 2 revisions

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

C#: sbyte

Довідник C# · Практичне керівництво

Знакове 8-бітове ціле число, від −128 до 127.

Простий приклад (Example.cs)

Збережіть цей приклад окремо як Example.cs. Запускайте його незалежно від інших прикладів на сторінці.

Example.cs:

// PROJECT-EXAMPLE
sbyte amount = 12;
System.Console.WriteLine(amount + 2);

Результат:

14

Синтаксис

sbyte value = 12;

Тип змінної визначає діапазон і правила арифметики. Для перевірки переповнення цілих чисел використовуйте checked; для перетворення тексту — TryParse.

Приклад 1: базова форма

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        sbyte first = 12;
        sbyte second = 2;
        Console.WriteLine(first + second);
    }
}

Приклад 2: інша практична форма

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        sbyte[] values = [12, 2, 3];
        foreach (sbyte value in values) Console.WriteLine(value);
        Console.WriteLine(sbyte.MaxValue);
    }
}

Офіційне джерело: Microsoft Learn.

Clone this wiki locally