Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
. Operator

. Operator

The dot operator is used for member access.

name1 . name2


A name.
A name.


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;
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

© 2015 Microsoft