Skip to content

JA CSharp Operator Assignment

Codex edited this page Oct 11, 2026 · 2 revisions

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

流用

ディレクトリ C# · 実践的な指導

値を変数または書き込み可能なメンバーに格納します。複合フォームでは、左辺の計算を重複せずに演算を適用し、結果を記録します。

簡単な例 (Example.cs)

この例を Example.cs として別に保存し、このページの他の例とは独立して実行してください。

Example.cs:

// PROJECT-EXAMPLE
int count = 2;
count += 3;
System.Console.WriteLine(count);

結果:

5

構文

value = expression / value += amount

例 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)
    {
        int value = 10;
        value += 5; value -= 2; value *= 3; value /= 2; value %= 7;
        Console.WriteLine(value);
    }
}

例 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)
    {
        int mask = 0b0011;
        mask |= 0b0100; mask &= 0b0111; mask ^= 0b0001;
        mask <<= 2; mask >>= 1; mask >>>= 1;
        Console.WriteLine(mask);
    }
}

公式ソース: Microsoft Learn。

Clone this wiki locally