Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

Member access: the dot operator (.)

The dot selects a member of an object or type and forms qualified names. Learn the difference between property access, method invocation, and conditional access when a receiver is null.

Version: .NET 10; repository net10.0 and LangVersion=preview; feature versions require per-entry verification

Syntax

expression.member
TypeName.StaticMember
NamespaceName.TypeName
expression.Method(arguments)

object.member denotes member access using .. Here, object is a placeholder for an expression referring to an object, not a required use of the object keyword. For example, text.Length reads an instance property. Access must respect the member's accessibility.

For a static member, use the type name: string.Empty. The dot also qualifies namespaces and types, as in System.Console. You can chain accesses: string.Empty.Length first obtains the empty string, then its length.

The dot alone does not call a method: in text.Substring(1, 3), it selects Substring, while () performs the invocation with arguments. Reading a property can, however, execute its get accessor; do not assume every access is a direct field read.

Ordinary . does not guard against null: reading an instance property through a null reference causes NullReferenceException. The separate ?. operator skips access when the receiver is null. The . operator cannot be overloaded.

Examples

using System;

internal static class Program
{
    private static void Main()
    {
        string text = "CKTIS";
        Console.WriteLine(text.Length);
        Console.WriteLine(text.Substring(1, 3));
        Console.WriteLine(string.Empty.Length);
    }
}

Result

5
KTI
0

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources