Export (0) Print
Expand All
Expand Minimize

Code: Calling a Method on an Object (Visual C#)

Visual Studio .NET 2003
 

This example calls the WriteLine method on the Console class.

Example

Console.WriteLine("This line will appear in the console window");

Compiling the Code

Copy the code and paste it into the Main method of a console application.

Robust Programming

Use the fully qualified name of the method, unless it is accessible from the same scope.

Unless the method is static, it must be referenced through an instance of the class.

When assigning an expression to a property, make sure of the following:

  • That it is of a compatible data type.
  • That it has a valid value, especially if the value is derived from user input.

See Also

Console Class | Console.WriteLine Method (String) | General Language Example Topics

Show:
© 2015 Microsoft