Chapter 3: Learning Just Enough C# and VB.NET: Types and Members

73

C#: (MessagePrinter.cs)

using System;

using System.Collections.Generic; using System.Linq;

using System.Text;

namespace FirstProgram

{

class MessagePrinter

{

public static void PrintMessageStatic()

{

Console.WriteLine("Hello from a static method.");

}

public void PrintMessageInstance()

{

Console.WriteLine("Hello from an instance method.");

}

}

}

VB (Module1.vb):

Module Module1

Sub Main()

MessagePrinter.PrintMessageShared()

Dim msgPrint As New MessagePrinter() msgPrinter.PrintMessageInstance()

End Sub

End Module

VB (MessagePrinter.vb)

Public Class MessagePrinter

Public Shared Sub PrintMessageShared()

Console.WriteLine("Hello from a shared method.")

End Sub

Public Sub PrintMessageInstance()

Console.WriteLine("Hello from an instance method.")

End Sub

End Class

Page 96
Image 96
Microsoft 9GD00001 manual # MessagePrinter.cs