Repository navigation
IT CSharp Operator Pointer
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
& ottiene l'indirizzo, * denomina il puntatore, -> accede al membro della destinazione del puntatore. Richiede conformità non sicura e a vita della memoria.
Salvare questo esempio separatamente come Example.cs. Eseguirlo indipendentemente dagli altri esempi di questa pagina.
Example.cs:
// PROJECT-EXAMPLE
unsafe
{
int value = 3;
int* pointer = &value;
*pointer = 7;
System.Console.WriteLine(value);
}Abilitare <AllowUnsafeBlocks>true</AllowUnsafeBlocks> nel progetto. Il puntatore è valido solo nell’ambito mostrato.
Risultato:
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; }Fonte ufficiale: Microsoft Impara.
ClassicUO — Bad Newbie & C# Scripts IDE