. Operator (C# Reference)
The dot operator (.) is used for member access. The dot operator specifies a member of a type or namespace. For example, the dot operator is used to access specific methods within the .NET Framework class libraries:
// The class Console in namespace System:
System.Console.WriteLine("hello");
Remarks
For example, consider the following class:
class Simple
{
public int a;
public void b()
{
}
}
Simple s = new Simple();
The variable s
has two members, a
and b
; to access them, use the dot operator:
s.a = 6; // assign to field a;
s.b(); // invoke member function b;
The dot is also used to form qualified names, which are names that specify the namespace or interface, for example, to which they belong.
// The class Console in namespace System:
System.Console.WriteLine("hello");
The using directive makes some name qualification optional:
using System;
// ...
System.Console.WriteLine("hello");
Console.WriteLine("hello"); // same thing
But when an identifier is ambiguous, it must be qualified:
using System;
// A namespace containing another Console class:
using OtherSystem;
// ...
// Must qualify Console:
System.Console.WriteLine( "hello" );
C# Language Specification
For more information, see the following sections in the C# Language Specification:
- 7.5.4 member access