Repository navigation
RU CSharp Operator Pointer
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Справочник C# · Практическое руководство
& получает адрес, * разименовывает указатель, -> обращается к члену pointer-цели. Требует unsafe и соблюдение времени жизни памяти.
Сохраните этот пример отдельно как 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->Memberusing 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); }
}
}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 Learn.
ClassicUO — Bad Newbie & C# Scripts IDE