call a method on an instance of a class in csharp

In C#, you can call a method on an instance of a class using the dot notation. Here's an example:

main.cs
// define a simple class
public class MyClass
{
    public void MyMethod()
    {
        Console.WriteLine("Hello world!");
    }
}

// create an instance of the class
MyClass myObj = new MyClass();

// call the method on the instance using dot notation
myObj.MyMethod();
272 chars
15 lines

In the example above, we define a simple class MyClass with a method MyMethod that writes "Hello world!" to the console. We then create an instance of the class myObj using the new keyword, and call the method MyMethod on the instance using dot notation (myObj.MyMethod()). This will write "Hello world!" to the console.

gistlibby LogSnag