The dot operator is used for member access.
name1 . name2
Where:
- name1
- A name.
- name2
- A name.
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, names that specify the namespace or interface (for example) to which they belong.
System.Console.WriteLine("hello"); // class Console in namespace System
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;
using OtherSystem; // a namespace containing another Console class
...
System.Console.WriteLine( "hello" ); // must qualify Console
See Also
C# Operators | 7.5.4 Member access