0

In C#, we do:

Console.WriteLine("C#");

In C++/CLI we use this syntax to use console object.

Console::WriteLine("C++ CLI");

We are using a .NET object Console in both places so why do we access its member function WriteLine() with dot(.) in C# project but with two colons in C++/CLI project?

From a book on C++/CLI, it says Console is a class in System namespace so why the :: operator? Is it a different console class all together? Is the system namespace also different from the one in C#? if so why they named it the same?

zar
  • 11,361
  • 14
  • 96
  • 178

1 Answers1

3

This is because WriteLine is a static method:

// C#
public static void WriteLine (string value);

and scope resolution operator :: is used to call static methods in C++

See How do I call a static method of another class (in C++)

Lesiak
  • 22,088
  • 2
  • 41
  • 65