By 22/07/2015 13 Comments

C# Dot Operator

  • It joins a class member with a class object name or a reference variable.

OR

  • It links the class member with its object.
  • A class member can be methods, properties, fields, events, constants etc.

Example:

using System;
namespace csharpBasic
{
  // Start class definition / declaration.
    class Program
    {
      // Static main method void type declaration.
        static void Main(string[] args)
        {
            // A new object of type Test class is being created.
            Test objTest = new Test();

            // Test class reference variable is (objTest) calling a field of Test classs through dot (.) operator.
            Console.WriteLine("Website name is: "+objTest.websiteName);

            // Test class reference variable (objTest) is calling a method of Test classs through dot (.) operator.
            objTest.DisplayMessage();
            Console.ReadKey();

        } // End of main method definition.

    } // End of class.

    class Test
    { 
        // Declare and initialize a string type field.
        public string websiteName = "TutorialsTown";

        public void DisplayMessage()
        {
            // A message is printed.
            Console.WriteLine("C# is an object oriented programing language.");
        } 
    } 
}






Next Tutorial →


← Previous Tutorial


Posted in: C# Basics, C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .