Skip to content

CSharp Keyword short

Codex edited this page Oct 11, 2026 · 2 revisions

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

C#: short

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

Знакове 16-бітове ціле число.

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

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

Example.cs:

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

Результат:

14

Синтаксис

short value = 120;

Тип змінної визначає діапазон і правила арифметики. Для перевірки переповнення цілих чисел використовуйте 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)
    {
        short first = 120;
        short 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)
    {
        short[] values = [120, 2, 3];
        foreach (short value in values) Console.WriteLine(value);
        Console.WriteLine(short.MaxValue);
    }
}

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

Clone this wiki locally