The Guru[ap]s Guide to SQL Server[tm] Stored Procedures, XML, and HTML

for RuBoard

That's a really good question. Microsoft has branded so many things with the .NET label that it's difficult to tell sometimes. Let me tell you what it means to me. First, the high-level view:

.NET is a set of technologies that

And now the specifics:

No discussion of .NET would be complete without at least a little dabbling in code. Listing 16-1 shows the source to a Hello World application in Visual Basic.NET. Note that I only wrote one line of codethe call to MsgBox() (in bold type). The rest was autogenerated by the IDE. I've left out the autogenerated property settings and form setup code because it's normally not displayed.

Listing 16-1 A simple Visual Basic.NET application.

Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MsgBox("Hello world!") End Sub End Class

As you can see, Visual Basic now supports object orientation and inheritance. Our form class (Form1) inherits from the base form class in the .NET Framework, System.Windows.Forms.Form. This base form class in actually written in C#, so you're seeing cross-language inheritance in actionsomething COM has never had.

The method Button1_Click() is a method of Form1. Clicking Button1 causes this method to execute and passes in a reference to the control that triggered it via the sender parameter.

Now here's the same app in C# (Listing 16-2):

Listing 16-2 A Hello World app in C#.

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace HelloWorldCS { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after // InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> public override void Dispose() { base.Dispose(); if(components != null) components.Dispose(); } /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender,System.EventArgs e) { MessageBox . Show("Hello world!"); } } }

Although there's a bit more code here than there was in the Visual Basic listing, I only wrote one line of it (in bold type). The rest was automatically created. If you're familiar with C and C++, the syntax probably looks very familiar to you. C# does not need or use header filesall definitions are inlinethat is, the implementation also serves as the interface. You decide what is or isn't visible to the outside world via modifiers (e.g., private, public, and so on).

for RuBoard

Категории