Skip to content

KO CSharp Operator Pointer

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
unsafe
{
    int value = 3;
    int* pointer = &value;
    *pointer = 7;
    System.Console.WriteLine(value);
}

프로젝트에서 <AllowUnsafeBlocks>true</AllowUnsafeBlocks>를 활성화하세요. 포인터는 표시된 범위 내에서만 유효합니다.

결과:

7

통사론

Type* pointer = &value; / *pointer / pointer->Member

예시 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)
    {
        unsafe { int value = 3; int* pointer = &value; *pointer = 9; 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)
    {
        unsafe { Point value = new() { X = 2 }; Point* pointer = &value; pointer->X += 5; Console.WriteLine(value.X); }
    }
}
public struct Point { public int X; }

공식 출처: Microsoft 학습.

Clone this wiki locally