Creating Methods

We were introduced to creating methods in Chapter 2, “Basic C# Programming,” but there are a few more considerations to add. First, as we saw in ch03_01.cs, Listing 3.1, methods can be declared with access modifiers, and that's important when you're creating objects. Declaring a method public makes it accessible outside an object, for example, whereas declaring it private locks it away inside the object.

Now that we're thinking in terms of objects and methods, it's also important to discuss the this keyword. This keyword works the same in C# as it does in C++, and it refers to the current object in which your code is executing. For example, say you're writing code to set up a button that appears in a window and you want to pass ...

Get Microsoft® Visual C#® .NET 2003 Kick Start now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.