Skip to content

EN CSharp Members

Codex edited this page Oct 11, 2026 · 2 revisions

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

Fields, properties, indexers and modifiers

Manual C# · Examples UO

public, private, protected, internal, protected internal and private protected specify availability. static refers to a type, readonly limits the field entry, const specifies a constant. The property uses get, set, or init; the indexer provides access via [].

Simple example (Example.cs)

Save this example separately as Example.cs. Run it independently of the other examples on this page.

Example.cs:

// PROJECT-EXAMPLE
var item = new Item();
item.Count = 7;
System.Console.WriteLine(item.Count);
class Item { public int Count { get; set; } }

Result:

7
sealed class Config
{
    private int delay = 100;
    public string Name { get; init; } = "default";
    public int Delay
    {
        get => delay;
        set => delay = Math.Clamp(value, 0, 5000);
    }
}

var config = new Config { Name = "Gather", Delay = 150 };
await WaitAsync(config.Delay);
UO.Print(config.Name);
sealed class Counters
{
    private readonly Dictionary<string, int> values = new();
    public int this[string name]
    {
        get => values.TryGetValue(name, out int value) ? value : 0;
        set => values[name] = value;
    }
}

var counters = new Counters();
counters["items"] = 3;
UO.Print(counters["items"].ToString());

required requires a member to be populated when an object is created. Object and collection initializers do not replace checking for valid game values. Partial types partial combine multiple declarations when compiling a single project.

Official Documentation: Fields, Properties, Indexers, and Modifiers - Microsoft Learn.

Clone this wiki locally