Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

. 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:

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:

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;
// A namespace containing another Console class:
using OtherSystem; 
// ...
// Must qualify Console: 
System.Console.WriteLine( "hello" );

For more information, see the following sections in the C# Language Specification:

  • 7.5.4 member access

Community Additions

© 2015 Microsoft