Code: Calling a Method on an Object (Visual C#)
This example calls the WriteLine method on the Console class.
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.
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.